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