Once I create dom elements base on json data with jtemplates, what is the best way to reorder those elements based on changes to the json data (sorting, filtering, etc.).
A:
Create new element, add child elements to this element, add parent element to the DOM.
Сергій
2010-02-11 17:22:07
A:
So the method I'm using to solve this right now is I added a numbered index to each of my templated sections of html like so:
<div id="list">
<div id="items-start"></div>
{#foreach $T as item}
<div id="item-{$T.item$index}" class="item">
...lots of stuff...
</div>
{#/for}
</div>
Then in my json items I added an attribute called InitialIndex to keep track of which dom item is associated with each item in the json. This way after I make any changes to my json data I can call this simple function to apply the changes to the dom:
function applyListChanges(items) {
$('.item').hide();
for (var item in items) {
var index = items[item].InitialIndex;
$('#items-start').append($('#item-' + index));
$('#item-' + index).show();
}
}
Please let me know if you have a better solution.
Ryan
2010-02-11 21:27:05
What does this have to do with the question?
Tauren
2010-09-10 20:32:24