0
我有一个路由器类,它实际上为视图和集合提供了单独的哈希,如下所述。当我在视图渲染方法中使用实例时,如何设置集合的url参数。实例化集合主干
Router类
Router = (function() {
'use strict';
var
viewHash = {},collectionsHash = {},
EvtCalRouter, startRouter;
// Set up the Backbone Router.
// Evaluates URL with parameters and maps them to functions contained within the Router.
// This enables us to do things like allow users to bookmark search results.
// See "http://backbonejs.org/#Router" for more info.
EvtCalRouter = Backbone.Router.extend({
// Define the Routes we care about.
// See "http://backbonejs.org/#Router-routes" for more info.
routes : {
"" : "home",
"route1" : "route1"
}
buildSearchScreen : function() {
collectionsHash['events'] = ESPN.apps.ADTG.EC.EventsCollection.newInstance({
});
},
startRouter = function() {
new EvtCalRouter();
Backbone.history.start();
};
// Start routing functionality
$(document).ready(startRouter);
// For any module that needs to know...
$(document).ready(function() {
$(document).trigger(ESPN.apps.ADTG.EC.events.ecInit);
});
//-------------------------------------------------------------------------------------------------------------------
// Public API
//-------------------------------------------------------------------------------------------------------------------
return {
getCollection : function(name){return collectionsHash[name]||{};}
};
})();
集合类放在这里
The Collection Class is defined like this
The Collection Class
Collection = (function(){
var Events;
Events = Backbone.Collection.extend({
initialize: function(props){
this.url = props.url;
alert(this.url);
}
});
return {
newInstance : function(options) { return new Events(options); }
};
})();
我想动态地设置网址,因为我在网页左侧点击水印,点击它们中的每一个将检索同一个集合的单独数据集。 – Vinay
然后你可以在你的集合中定义url作为一个函数。如果你的url的大部分是相同的。如果他们不是,他们指向不同的控制器,你真正需要做的是...定义不同的集合。查看我答案中最后添加的部分。 –
我做了var eventsCollection = ESPN.apps.ADTG.EC.Router.getCollection('events'); ''; http:// localhost:8080/adtglobal/2.0/api/events?startDate = 2013-11-05T00:00:00-0400&endDate = 2013-11-06T00:00:00-0400');我得到一个错误eventsCollection.url不是一个函数。 – Vinay