出于某种原因,当我获取它时,我的集合被设置为undefined。如果我在获取之前记录集合,我实际上得到了这个:
http://i.stack.imgur.com/CdPH0.png
如果我在获取后记录它(当触发同步事件时),我得到了未定义。
App.Views.Overview = Backbone.View.extend({
template:tpl.overview,
tagName:"div",
id:"overview",
initialize:function () {
console.log('Initializing Overview');
this.collection.on("sync reset",this.render);
},
render:function () {
console.log(this.collection);
$(this.el).html(this.template);
return this;
}
});
App.Collections.Gardens = Backbone.Collection.extend({
model: App.Models.Garden,
url: Settings.API + "/gardens"
});
App.Models.Garden = Backbone.Model.extend({
defaults:{
id:"undefined",
owner_id:"undefined",
name:"undefined",
width:"undefined",
height:"undefined"
}
});
这是我创建视图的方式:
var gardens = new App.Collections.Gardens();
gardens.fetch();
this.overview = new App.Views.Overview({collection: gardens});
提前致谢!