0

オブジェクトの配列がいくつかあります。

data = [
{
'showname-array': [
    {'a':..}
    {'b':..}
    {'c':..}
]
},
{
'andanotherName-array': [
    {'a':..}
    {'b':..}
    {'c':..}
]
},
]

mustacheまたはunderscore.js-templatesでオブジェクトのプロパティの名前をレンダリングすることは可能ですか:'showname-array''andanotherName-array'

<div> Hello , showing content of: <% showname-array %> </div> 

どうしてそれは可能ですか?

4

1 に答える 1

1

アンダースコア_.keys()機能を使用できます

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>
于 2011-09-15T10:17:38.543 に答える