小胡子用顶级钥匙迭代json

时间:2013-08-20 18:36:37

标签: 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 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": []
        }
}

用Handlebars可以轻松完成吗?我似乎无法找到在模板内自动迭代的方法。现在我有:

{{#content}}
{{#arr}}
<li>
{{text}}
</li>
{{/arr}}
{{/content}}
</script>
var html = Mustache.to_html(template, {content:arr});

0 个答案:

没有答案
相关问题