问题
is it possible to check for duplicate Dom elements while rendering a jsrender.template?
For example:
if element doesnt exists use this:
<li id="liv_{{:nid}}"> <div class="qwqw"><a href="#"></a></div> <div class=""> <p class="we">{{:spd}} <span>mph (todo)</span></p> </div> <div class="clear"></div> </li>
if the element "liv1" exists then update the view and dont perform step 1.
回答1:
Try to use helper functions
Templates pseudo code:
{{if ~domElementExists(id)}}
...
{{/if}}
Helper's pseudo code
$.views.helpers({
domElementExists: function( id ) {
return $("#liv_" + id).length > 0;
}
});
来源:https://stackoverflow.com/questions/13018124/how-to-avoid-duplicate-rendering-of-dom-elements-in-jsrender