[英]More than one events are added to an inner view backbone?
所以在这里我有两个视图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;
现在第二个和内部视图
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/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.