【发布时间】:2013-08-12 15:34:44
【问题描述】:
我初始化视图:
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 中的徽章编号。
【问题讨论】:
标签: jquery backbone.js coffeescript backbone-events