4
我是Backbone JS的新手,一直關注着Christopher Coenraets Wine Cellar tutorial。Backbone JS - this.model.models而不是this.collection?
這一切工作正常和丹迪,但我不明白他如何使用this.model.models
訪問收集而不是this.collection
。此外,當我嘗試將代碼更改爲後者時,看起來this.collection
未定義。
window.WineListView = Backbone.View.extend({
tagName:'ul',
initialize:function() {
this.model.bind("reset", this.render, this);
},
render:function (eventName) {
_.each(this.model.models, function (wine) {
$(this.el).append(new WineListItemView({model:wine}).render().el);
}, this);
return this;
}
});
'models'是Collection對象的成員。 Collection被分配給的名稱('model' vs'collection')就像其他變量名一樣,並且與包含的對象類型沒有關係。 –