Javascript Mustache使用顶级键在json上迭代
希望在此处迭代每个“内容”项:Javascript Mustache使用顶级键在json上迭代,javascript,mustache,templating,Javascript,Mustache,Templating,希望在此处迭代每个“内容”项: "content": { "0": { "artifact_id": "36", "timestamp": "2013-08-20 11:59:00", "modified": "2013-08-20 11:59:00", "text": "Why did the last one duplicate? I don't think I click
"content": {
"0": {
"artifact_id": "36",
"timestamp": "2013-08-20 11:59:00",
"modified": "2013-08-20 11:59:00",
"text": "Why did the last one duplicate? I don't think I clicked it twice...",
"author_desc": "",
"object_type": "artifact",
"comments": []
},
"1": {
"artifact_id": "35",
"timestamp": "2013-08-20 11:57:51",
"modified": "2013-08-20 11:57:51",
"text": "This is a new artifact for a new day.",
"author_desc": "",
"object_type": "artifact",
"comments": []
},
"2": {
"artifact_id": "34",
"timestamp": "2013-08-20 11:57:50",
"modified": "2013-08-20 11:57:50",
"text": "This is a new artifact for a new day.",
"author_desc": "",
"object_type": "artifact",
"comments": []
}
}
有没有可能用把手轻松做到这一点?我似乎找不到在模板内自动迭代的方法。现在我有:
{{#content}}
{{#arr}}
<li>
{{text}}
</li>
{{/arr}}
{{/content}}
</script>
var html = Mustache.to_html(template, {content:arr});
{{#content}
{{{#arr}
{{text}}
{{/arr}}
{{/content}
var html=Mustache.to_html(模板,{content:arr});
简言之,请参见:使用Handlebar 1.0rc1时,请使用{{{#each object}}获得它。。从一开始就应该使用把手!