在主干模型中,对于嵌套视图,是否可以在初始化函数中触发事件?我基于此示例的当前代码:https ://stackoverflow.com/a/8523075/2345124并已将其更新为骨干网 1.0.0。这是我的初始化函数,用于模型:
var Edit = Backbone.Model.extend({
initialize: function() {
this.trigger('marquee:add');
this.on('change', function(){
this.trigger('marquee:add');
});
}
...
}
我正在尝试在模型初始化时调用方法 renderMarquee:
var EditRow = Backbone.View.extend({
initialize: function() {
this.listenTo(this.model, "change", this.render); // works
this.listenTo(this.model, "marquee:add", this.renderMarquee); // only called when changed, but not when initially created
...
}
renderMarquee在模型更改时调用,但在初始化时不调用。'change' 事件按预期工作(调用 this.render)。有什么想法吗?
谢谢!