我初始化视图:
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
通知.咖啡
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 中的徽章编号。