所以这里我有两个 View addBook 和 showBooks ,想法是,当我单击按钮时,它应该将书名和作者添加到 DOM 中,它是
var addBook = Backbone.View.extend({
el : $('#addbook'),
model : bookmodel,
template : _.template(addbookTemplate,{}),
initialize : function(val){
this.el.html(this.template);
bookcollection.bind('add', this.showOff)
},
render : function(){
},
events : {
'click #addbookbutton' : 'addHandler'
},
addHandler : function(){
var book = new this.model;
book.addValues($('#bookname').val(), $('#bookauthor').val());
bookcollection.add(book);
},
showOff : function(buk){
this.xx = new showval({model: buk});
$('#fatman').append((this.xx.render().el));
}
});
return addBook;
现在是第二个内部 View
var showbooks = Backbone.View.extend({
events : {
'click .individual' : 'deleteHandler'
},
initialize : function(values){
_.bindAll(this);
/*if(values){*/
//return this.template;
//}
//values = (values == "") ? {} : values;
this.el.append(this.template);
},
render : function(){
this.el = _.template(show, {name : "Max", author : "jk"});
this.delegateEvents();
return this;
},
deleteHandler : function(e){
alert("this kills me")
}
});
return showbooks;
现在,当我单击按钮时,问题就出现了
最佳答案
我已经拿走了你的代码并稍作修改。我创建了 2 个 Backbone.View,一个作为容器,另一个用于书籍项目。虽然很粗糙,但希望能让您了解哪里出了问题。 http://jsfiddle.net/cQEu2/
关于javascript - 是否将多个事件添加到内部 View 主干?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15186777/