Reputation: 21
Hi i am using the jTemplates for rendering the data through html controls, By using
$('div#table-jtemplates').setTemplate(x);
$('div#table-jtemplates').processTemplate(data);
Can i append the data to the specific div.by above i am able to replace the whole data. can any one help me out of this.Thanks in advance
Upvotes: 0
Views: 326
Reputation: 127
jtemplates works by processing whats in the template against the data you are sending it
if you want to APPEND more data, you'd need to do a loop in the template itself
e.g.
<div id='mydiv'>
{#foreach $T.years as year}
<td class="aright bt italic cyear_{$T.year}" id="total_super_{$T.year}">0</td>
{#/for}
</div>
Then you'd:
$('new div').setTemplate("mydiv");
$('new div').processTemplate({years: [1,2,3,4]});
As there are 4 years it would create 4 of these elements
Upvotes: 0
Reputation: 752
Ive not worked on jTemplates ,but by the look of it if you want to append data to specific div then take the html inside that div in a seperate template and then process it. like you have already done:
$('new div').setTemplate("new template created with divs html");
$('new div').processTemplate(data);
Upvotes: 0