javascript - mustache js - Can't access array value using tables -
javascript - mustache js - Can't access array value using tables -
i having problem mustache.js accessing values of json array , need help.
the problem when want access values using table. shows [object object]
, when should show array content.
below working , non-working example:
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="https://raw.github.com/janl/mustache.js/0.7.2/mustache.js"></script> </head> <body> <div id="template" style="display:none"> <p>works not need:</p> <p>{{#numbers}} {{.}} {{/numbers}} </p> <p>doesn't work:</p> <table> <tr> {{#numbers}} <th> {{.}} </th> {{/numbers}} </tr> </table> </div> <div id="rendered"></div> <script> var json = { "numbers": [ 1, 2, 3 ] }; var compiledtemplate = mustache.to_html($('#template').html(), json).replace(/^\s*/mg, ''); $('#rendered').html(compiledtemplate); </script> </body> </html>
output is:
works not need: 1 2 3 doesn't work: [object object]
is there way solve problem or print object attributes using mustache.js?
the issue asked in issue system, no replies yet: https://github.com/janl/mustache.js/issues/295
thanks, mariano.
finally, did.
replaced div element template, script element:
from <div id="template" style="display:none">
<script id="template" type="text/x-mustache-template">
and worked expected =)
javascript templates mustache
Comments
Post a Comment