javascript - Marionette JS : updating all ItemViews in a CompositeView after a 'change' event in the DOM

标签 javascript backbone.js marionette

更改与 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/

相关文章:

JavaScript,将值传递给函数

javascript - 在验证器中添加自定义规则以检查 <ul> 是否有元素

javascript - jQuery 重新渲染/绘画错误

javascript - Backbone View +谷歌可视化API

marionette - 依赖Application的event mixin和Application.vent有什么区别?

javascript - 如何使用不平坦的数据创建主干集合

javascript - Ember 重定向仅在您第一次进入路线时触发

javascript - 为什么我的 Netbeans 8 javascript 自动完成功能在我的 AngularJS 项目中不起作用?

javascript - 使用 Jasmin 和 Sinon 对 Backbone 类构造函数进行 stub

javascript - 将 Handlebars Helpers 作为参数传递给 #if