how can I render this JSON use mustache.js without loop

左心房为你撑大大i 提交于 2019-12-06 10:30:54

here is one way to do the same with just mustaches templates. you set your data as follows:

 var data = {data: [
    {
        "event": {
            "name": "txt1",
            "data": "2011-01-02",
            "address": "Guangzhou Tianhe Mall"
        }
    },
    {
        "event": {
            "name": "txt2",
            "data": "2011-01-02",
            "address": "Guangzhou Tianhe Mall"
        }
    },
    {
        "event": {
            "name": "txt3",
            "data": "2011-01-02",
            "address": "Guangzhou Tianhe Mall"
        }
    }
]};

and your template should look as follows:

{{data}}
{{#event}}
<div>
<h2>{{name}}</h2>
<span>on {{data}}</span>
<p>{{address}}</p>
</div>
{{/event}
{{/data}}

Hope that helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!