在我的函数中,即使我添加了重置以触发我的渲染函数,但什么也没有发生......任何线索我错了我做了什么......?
代码:
$(document).ready(function(){
var school = {};
school.model = Backbone.Model.extend({
defaults:{
name:'name yet to decide'
}
});
school.collect = Backbone.Collection.extend({
model:school.model,
url:'js/school.json',
parse:function(response){
return response;
}
});
school.view = Backbone.View.extend({
tagName:'div',
className:'division',
template:$('#newTemp').html(),
render:function(){
var temp = _.template(this.template);
this.$el.html(temp(this.model.toJSON()));
return this;
}
});
school.views = Backbone.View.extend({
el:$('#content'),
initialize:function(){
_.bindAll(this);
this.collection = new school.collect;
this.collection.bind("reset", this.render);
this.collection.fetch({
update:true
})
},
render:function(){
var that = this;
_.each(this.collection.models, function(item){
that.addItems(newItem);
})
},
resets:function(){
console.log(this.collection.models)
console.log('calling from resets')
},
addItems:function(item){
var newItem = new school.collect({model:item});
this.$el.append(newItem.render().el);
},
changed:function(){
console.log('calling from changed')
}
});
var newSchool = new school.views;
})