更改与 ItemView
中的单个属性相对应的输入文本字段后,我会更新 CompositeView
中的所有模型。
更新在模型中运行良好,但只有与上次编辑的输入文本字段对应的 ItemView 才会在 DOM 中显示新属性,因为它是 CompositeView
中唯一获取其 onRender
方法调用:
onRender: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
我想在CompositeView
内的所有ItemViews
中再次调用onRender()
函数。我怎样才能做到这一点?
最佳答案
阅读 this question 中出现的内容后,以及检查文档。我想我应该尝试在 ItemView
中简单地使用 change
事件监听器。
myItemView = Backbone.Marionette.ItemView.extend({
initialize: function() {
/*bind change event, will get onRender fired when the probability gets updated
this.model.bind('change', this.onRender);
error: 'cannot call' Cannot call method 'toJSON' of undefined
TODO: figure out WHY this is an error but this.render is OK*/
this.model.bind('change', this.render);
}
奇怪的是,onRender()
失败了,但是 render()
完成了这项工作。现在我想弄清楚为什么。
关于javascript - Marionette JS : updating all ItemViews in a CompositeView after a 'change' event in the DOM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18777106/