可观测集合发生变化时更新Div

Updating Divs when observable collection changes

本文关键字:更新 Div 变化 集合 可观      更新时间:2023-09-26

当项目被添加/删除到可观察集合时,是否有任何插件或jquery实用程序会更新绑定到该集合的div列表?我们有1000个项,因此正在寻找在绑定列表更改时添加/删除div的最佳方式。

我们有兴趣在KO或jquery.tmpl.中了解这一点

这可能不是你想要的答案,但这可能是一种方法。我会将数组包装在一个具有Add and Remove方法(或其他更改数组的函数)的对象中

var Collection = (function () {
    var collectionArray = new Array();
    //"private" methods
    function updatePageDivs()
    {
        //Logic to update your Divs
    }
    //"public" methods
    return{
        Add: function(element){
            collectionArray[collectionArray.length] = element;
             updatePageDivs();
        },
        Remove: function(element){
            //other logic to remove elements and to trigger the updatePage
        }
    }
});

您现在可以拨打

Collection.Add()

Collection.Remove()

以更改您的javascript集合。两者都会更新您的pagediv。