简体   繁体   English

仅重新渲染Marionette.js CollectionView的已更改部分

[英]Re-render only changed section of Marionette.js CollectionView

Below is the code I currently have that re-renders a collectionView on every addition or removal of a model. 下面是我目前拥有的代码,可以在每次添加或删除模型时重新呈现collectionView。 However, it seems inefficient as it has to render the whole thing every time, when all I really need is one modelView to be removed or one to be added. 然而,它似乎效率低下,因为它必须每次渲染整个事物,当我真正需要的是一个要删除的modelView或一个要添加的。 So how could I achieve this? 那我该怎么做呢?

var CollectionView = Marionette.CollectionView.extend({

    childView: ModelView,

    initialize: function() {
        [ "add", "remove" ].forEach(function(eventName) {
            this.listenTo(this.collection, eventName, this.render, this);
        }.bind(this));
    }

});

Thanks in advance for any help you can give! 在此先感谢您提供任何帮助!

This is already done automatically in Marionette : 这已在Marionette中自动完成:

When a model is added to the collection, the collection view will render that one model in to the collection of item views. 将模型添加到集合时,集合视图会将一个模型呈现到项目视图集合中。

When a model is removed from a collection (or destroyed / deleted), the collection view will close and remove that model's item view. 从集合中删除模型(或销毁/删除)时,集合视图将关闭并删除该模型的项目视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM