0
我的,我想在一個web應用程序,顯示模式幾個列表,所以我創建了一個通用類,如下所示:Backbone.js的:房產在子類View是未定義
App.ModelListView = Backbone.View.extend({
initialize: function() {
this.collection.bind('reset', this.addAll, this);
this.collection.bind('add', this.addOne, this);
this.collection.bind('remove', this.removeOne, this);
},
addAll: function() {
this.removeAll();
this.collection.each(this.addOne, this);
},
...
});
對於每個模型類型,我子類App.ModelListView
像這樣:
App.ProjectListView = App.ModelListView.extend({
el: $("#project-list"),
collection: App.Projects,
listItemView: App.ProjectListItemView
});
當我使用實例
App.ProjectMainListView = new App.ProjectListView();
視圖
我發現當App.ModelListView
的initialize
函數執行時,'this.collection'是未定義的。爲什麼在我使用的子類中定義的值不是collection
?我在這裏錯過了什麼?
你說得對!我將「App.Projects」的定義移至「App.ProjectMainListView」之前,並且一切都很好。應該抓住那個... – 2012-02-10 05:00:46