我与导轨API一个Backbone.js的应用程序,它提供了JSON工作,如下所示:Backbone.js的单击事件不工作consistantly
{
"name": "dan brown",
"genre": "fiction",
"books": [{
"title": "Da vinci Code",
"price": "50"
},
{
"title": "Some other name",
"price": "45"
}],
"name": "Author1",
"genre": "comedy",
"books": [{
"title": "asdfasdfdsf",
"price": "50"
},
{
"title": "asdfdsf name",
"price": "45"
}]
}
TODO: 1.要显示的列表作者在页面的左侧。 2.当用户点击提交,相应的书籍应该用链接显示add_to_cart 3.最后,当用户点击的书,它应该显示关于这本书
进展的详细信息: 1.我能够获得使用Backbone.js的并显示在左侧作者列表(authors.fetch()) 2,我能得到那个特定作者的书籍展现出来用户点击时。
问题:现在,当用户点击该作者1,第一次它会点击其他一些作家后显示作者但的书,如果在同一个作者1,用户点击一次没有书显示..似乎用户骨干作家模型失去点击事件后,它被点击一次....我想点击事件坚持作者...
怎么办?
在哪里做?
任何帮助和建议高度赞赏
在AuthorView
events: {
"click .author": "select"
},
select: function() {
this.collection.trigger('select', this.model);
//console.log(this.model);
}
在BookListView:
this.collection.bind('add', this.renderBook);
this.book = this.options.book;
this.authors = this.options.authors;
this.authors.bind('select', this.queueBooks);
queueBooks: function(author) {
this.collection.add(author);
}
我猜测,问题就出在queueBooks:方法,当一个模型被添加到 汇编它会触发一个添加事件,然后通过renderBook回调来渲染书籍...所以我认为如果模型已经存在于集合中,它不会触发添加事件,从而不会渲染书籍....如何解决这个?????? !!!!!!!!!!!!!!!
编辑:正如Derick-建议
this.authors = this.options.authors;
this.authors.bind('select', this.renderBooks);
这工作完全但是按照bieng不加模型集合中产生这样没有添加事件的.....我希望BookList集合中的书籍模型的原因是在booklist集合上有一个过滤器,以便它们可以根据价格和其他条件进行过滤,是否有任何方法可以实现这些功能?????????
谢谢完美的作品......如果可能的话,你可以建议一种在书籍集合上实现过滤的方法 – railerhelper