【发布时间】:2013-12-11 14:28:53
【问题描述】:
无法将我的数据放到我想要的位置。
在我的路由器中,我有一个传递 ID 的函数,如下所示:
routes: {
'deck/:id': 'getDeckId'
},
getDeckId: function(id) {
this.loadView(new DeckView())
},
loadView: function(view) {
this.view && (this.view.kill ? this.view.kill() : this.view.remove());
this.view = view;
}
在我的收藏中,我加载了一个 JSON 文件。在该 URL 中,我想添加我在路由器中传递的 ID。
var DeckCollection = Backbone.Collection.extend({
model: DeckModel,
url: "myUrl"+id, //the id i passing from my router
parse: function (response) {
return response;
},
initialize: function() {
},
return DeckCollection;
});
景色
var DeckView = Backbone.View.extend({
//initialize etc
});
所以当视图初始化时,我想用从路由器传递的 ID 加载这个 JSON。我该怎么做?
【问题讨论】:
标签: backbone.js