We have some array of objects:
data = [
{
'showname-array': [
{'a':..}
{'b':..}
{'c':..}
]
},
{
'andanotherName-array': [
{'a':..}
{'b':..}
{'c':..}
]
},
]
Is it possible to render with mustache or underscore.js-templates the name of object's property: 'showname-array' 'andanotherName-array'
<div> Hello , showing content of: <% showname-array %> </div>
How is i开发者_运维百科t possible?
You can use Underscore _.keys()
function
temp = "<% _.each(_.keys(data), function(name){ %>
<div>Hello, showing content of '<%= name %>'</div>
<% }); %>"
_.template(temp, data); // <div>Hello, showing content of 'showname-array'</div>
// <div>Hello, showing content of 'andanotherName-array'</div>
精彩评论