我有下一个代码:
var Contents = Backbone.View.extend({
events: {
"click #addAll": "addContent"
},
initialize: function() {
_.bindAll(this);
this.model = new ContentCollection();
this.model.on("add", this.contentAdded);
},
addContent: function(event) {
this.model.add({ modelName: "all"});
//Plugin event
$('select').switchify().data('switch').bind('switch:slide', function(e,type){
//Do something
});
},
contentAdded: function(content) {
if (content.view == null) {
var template_name;
switch(content.get("modelName")){
case 'all': template_name = 'home'; break;
}
content.view = new ContentView({
model: content, template: //template
});
$(".box").empty();
content.functionModel();
//render template
}
},
});
单击按钮 ( #addAll
) 时,模型会添加到集合中,然后创建视图、functionModel
调用视图并渲染模板。我想funtionModel()
在插件事件完成时执行,但 content
对于调用该函数的特定模型是必需的。并且该插件在contentAdded
.