I have following problem
DATA:
var json = {'data': [{'id': '1', 'members': [{'name':'First member', 'age': '23'},{'name':'Second member', 'age': '31'}] }]}
JSON is written from the top of my head so it may be invalid, not so important.
MUSTACHE.tmpl
{{#data}}
{{#members}}
<script>myJsFunction( all_members_attributes_as_json )</script>
{{/members}}
{{/data}}
So in general, I’d like to pass whole mustache array to my JS function
About like this:
Add a function for mapping your members to JSON strings:
Note that I used
_.eachand_.maphere… If you don’t use Underscore, replace with your favorite iterators, or a vanilla for loop. Or just use Underscore, because it makes life better.Then you’d access the stringified versions instead of the normal ones: