我collection.fetch不起作用,并没有得到要呈现的模型。 我有这个在我的router.js没有模型在提取collection.fetch骨干
itemcollection = new ItemCollection();
itemcollection.fetch();
ItemListView.render();
CartListView.render();
}
我itemcollection.js
define([
'underscore',
'backbone',
'model/item_model'
],function(_, Backbone, Item){
var ItemCollection = Backbone.Collection.extend({
model: Item,
url: 'http://posbeta.interprisesolutions.com/POSMobileConnector/Product/loaditembycategory/Event Materials',
parse: function(response) {
return response.Items;
}
});
return ItemCollection;
});
我的观点:
initialize: function(){
ItemCollection.bind("reset", this.render);
},
render: function(){
var data = {
items: itemcollection.models
}
var compiledTemplate = _.template(ItemListTemplate , data);
$("#itemContainer").html(compiledTemplate);
},
有趣的是,当我使用Firebug它调试它正确呈现当我删除断点时,它不显示任何东西。有任何想法吗?
我有重置,但它不工作。 ItemCollection.bind(“reset”,this.render); – jongbanaag 2012-04-02 07:33:16
您可能需要绑定'this':'ItemCollection.on('reset',this.render,this);' – stusmith 2012-04-02 07:43:30
我想要求澄清。如果我已经在itemlist视图上实例化了ItemCollection,我是否需要再次实例化它,如果我想在另一个视图上使用它呢? – jongbanaag 2012-04-02 07:54:39