Updating Divs on observable collection changes
Is there some plugin or jquery utility that will update my list of divs bound to an observable collection when items are added / removed to that collection? We have 1000 elements, so we are looking for the best way to add / remove divs when the linked list changes.
We'd be interested to hear about this in KO or jquery.tmpl.
+3
source to share
1 answer
This may not be the answer you are looking for, but it might be one way to do it. I would wrap the array in an object that has an Add and Remove method (or some other function that changes the array)
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
}
}
});
Now you can call
Collection.Add()
and
Collection.Remove()
to change your javascript collection. Both will update your pagers.
+1
source to share