My situation is as follows:
I receive an object from an AJAX call which contains an array of strings (not key/value pairs). It would be amazing if I could just take that array and toss it into the template's data object like the below, and then recursively show each value in the array via the ICanHaz mustache
section template syntax. Unfortunately I can not get it to work without key/value pairs to reference inside the section template.
This is a major pain because I have to go into the array returned from AJAX and add key value pairs.
I could not find anything on the mustache or ICanHaz.js documentation dealing with this matter.
Javascript:
var listOfStuff = {
name: 'This is not important',
stuff: data.ajaxreturnedarray || [1, 2, 3, 4] // Just for example.
};
$("#new").append(ich.test(listOfStuff));
HTML
<div id="new">Test</div>
<script type="text/html" id="test">
<div class="panel">
{{#stuff}}<p>{{stuff}}</p>{{/stuff}}
{{^stuff}}<p>No items :(</p>{{/stuff}}
</div>
</script>
Does anyone know a way to make this work?
Update
This is covered in this answer, but it does not mention ICanHaz.js
so I cross-reference for anyone googling this problem with ICanHaz.js without mustache
.
AFAIK, ICanHaz embeds Mustache, and if it's Mustache you can simply do