javascript - MustacheJS partials not rendering -
i trying use partial simple object enumerable property, partials won't render.
here link sample.
the object
obj6 = { people : [ { firstname : 'jayson', lastname : 'buquia', ismale : true }, { firstname : 'jane', lastname : 'doe', ismale : false }, { firstname : 'john', lastname : 'smith', ismale : true } ] };
the partials
partials = { person : '<li>{{ firstname }} {{ lastname }}{{^ismale}}, female {{/ismale}}.</li>' }
the template
<ul> {{ #people }} {{>person}} {{ /people }} </ul>
try change tpl = $('.template .main').html()
tpl = $('.template .main').text()
html()
wll return <h3>names:</h3><ul>{{ #people }} {{>person}}{{ /people }}</ul>
not valid template.
var $p = $('#container'), tpl = $('.template .main').text(), partials = { person : '<li>{{ firstname }} {{ lastname }}{{^ismale}}, female {{/ismale}}.</li>' }, obj6 = { people : [ { firstname : 'jayson', lastname : 'buquia', ismale : true }, { firstname : 'jane', lastname : 'doe', ismale : false }, { firstname : 'john', lastname : 'smith', ismale : true } ] }; $p.append(mustache.render(tpl,obj6,partials));
or convert div script
tag templete here demo:-
Comments
Post a Comment