我初始化查看:骨干事件
notifications = new tvr.notifications.Collection
notifications.fetch()
new tvr.notifications.View collection:notifications
林加入 “通知”,以骨干集合:
notifications = new tvr.notifications.Collection
notifications.fetch()
notifications.create html:this_notification
notifications.coffee
class Notifiction extends Backbone.Model
class Notifictions extends Backbone.Collection
model = Notifiction
localStorage: new Backbone.LocalStorage 'tvr.notifications'
class NotificationView extends Backbone.View
initialize: ->
@listenTo @collection, "add", @update
update: ->
alert "update"
namespace 'tvr.notifications', (exports) ->
exports.Model = Notifiction
exports.Collection = Notifictions
exports.View = NotificationView
这个事件从不被调用,我可以看到集合中创建的对象。
我只想知道何时添加新的或从集合中删除了新的,因此我可以更新HTML中的徽章编号。
我照你解释,但是这是行不通的。我更新了我的问题 – Harry
您可能需要'_.bindAll(this)'作为'initialize'函数的第一行。另外,我看不到任何证据表明您正在为'Notifictions'集合添加模型。你在你的例子中甚至没有对它的引用,因为你在'listenTo'函数中'new'。那么你怎么能为它添加模型呢? – dcarson
它在问题中,第1行和第2行。生病尝试bindAll – Harry