I want to use mustache to template some data. The data to template is like :
var data = {
"lib" : "L1",
"group" :
{"echelle" : "Bassin"}
}
I try to use mustache :
var templateResult = "<tr><td><p>{{lib}}</p></td><td><p>{{>group}}</p></td></tr>";
var partials = {"group" : "{{#group}}<td><p>{{echelle}}</p></td>{{/group}}"}
$("#result_indic_table").append(Mustache.render(templateResult, data, partials));
And it just doesn't work... What am i doing wrong?
I've solved my problem... the data wasn't like I thought :
data = {
"indicateur" : {
"lib" : "L1",
"group" :
{"echelle" : "Bassin"}
}
}
So the template should look like :
var templateResult = "{{#indicateur}}<tr><td><p>{{lib}}</p></td><td><p>{{>group}}</p></td></tr>{{/indicateur}}";
var partials = {"group" : "{{#group}}<td><p>{{echelle}}</p></td>{{/group}}"}
And it's done.
The problem with mustachejs is being what it is. I'd rather go for Swig
or Dust.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.