Sunday, 15 July 2012

jsrender - Possible to make more iteration than element count? -



jsrender - Possible to make more iteration than element count? -

recently started utilize jsrender, client needs table 5 rows, if there're 3 info items, table filled 3 rows , leave other 2 blank.

when utilize jsrender, used template following,

<script id="tmpoperation" type="text/x-jsrender"> <tr> <td>{{:name}}</td> </tr> </script>

my problem is, not generate 5 rows if info item less 5, how can generate blank table rows ?

=====update

for data:

data=[ {name:'aaa'}, {name:'bbb'}, {name:'ccc'} ]

code render:

var template = $.templates("#tmpoperation"); var html = template.render(data); $("#tbody_report").html(html);

html code:

<table > <tbody id="tbody_report"> </tbody> </table>

now there's 3 elements in it, there table 3 rows, need 5 rows ( 3 rows filled , other 2 blank), thanks.

the easiest way add together blank objects end of data array, either on server-side or client side. here's javascript work after you've retrieved data , before you've passed template.

for (var = 5 - data.length; > 0; i--) { data.push({name: ''}); }

jsrender

No comments:

Post a Comment