如果我在初始化方法中绑定到路由器事件,则调用回调:
var View = Backbone.View.extend({
initialize: function() {
router.on("route:test", this.update);
},
update: function() {
console.log('This works');
}
});
但这不起作用:
var View = Backbone.View.extend({
events: {
"route:test": "update"
},
initialize: function() { },
update: function() {
console.log('This never gets called');
}
});
在第二种情况下我做错了什么,还是我误解了什么?
events
仅在 DOM 级事件的视图内?