javascript - Mustache.js getting current Index of an array -
on initial page load, loading large json data object news feeds. using mustache.js , listing new feed headlines working great.
we have div area display details of onclick news item. since have data loaded, need pass index of current item (array index) grab news item need details from.
{{#data}} <li> {{eventname}}<br /> {{eventlocname}}<br /> {{eventloccity}}, {{eventlocst}} </li> {{/data}} i add id
{{#data}} <li id='{{data.index}}'> {{eventname}}<br /> {{eventlocname}}<br /> {{eventloccity}}, {{eventlocst}} </li> {{/data}} what syntax array index mustache.js template?
updated / working
once results onto dom, used following js add 'index' each array item. (select answer below code helped)
for (i in result) result[i].index = i;
i'm sorry... think need manually add index:
for (i in data) data[i].index = i; and
{{#data}} <li id='{{index}}'> {{eventname}}<br /> {{eventlocname}}<br /> {{eventloccity}}, {{eventlocst}} </li> {{/data}}
Comments
Post a Comment