骨干中的收集和查看
var studentmodel = Backbone.Model.extend();
var studentcollection = Backbone.Collection.extend({
model : studentmodel,
url : 'http://localhost/bb/data.JSON',
parse : function(response){
//console.log(response.data);
return response.data;
//return response;
},
});
var studentlistview = Backbone.View.extend({
tagName : "ul",
className : "studentlistul",
initialize : function(){
this.model.bind("reset", this.checkEvent,this);
this.model.bind("add", this.checkEvent,this);
},
checkEvent : function(){
$(this.el).html("");
_.each(this.model.models, function(student){
$(this.el).append(new studentListItemView({ model : student}).render2().el);
}, this);
$('#studentlistdiv').html($(this.el));
return this;
} });
并尝试将项目添加到此模型及其工作中,我的问题是在 render fn 中我如何在 this.model.bind("add", this.checkEvent,this) this evt 触发时获取事件类型。在 checkEvent 中,我如何获取事件的类型,即触发添加或重置的事件类型。这是我的问题请帮助我