Javascript, mustache.js, 如何

Javascript, mustache.js, how to

我正在使用 mustache.js 将我的页面放在一起,在一个事件中我捕获了一个 json 对象,我将其保存在一个变量中,代码如下所示:

{
    "result": [
        {
            "first": null,
            "second": "something",
            "third": "etc"
        }, {
            "first": null,
            "second": "something",
            "third": "etc"
        }, {
            "first": null,
            "second": "something",
            "third": "etc"
        }
    ]
}

我不知道在模板上使用什么胡子结构来显示 table 中的数据。好像数组是不规则形状的,我想把它变成table。有任何想法吗?谢谢。

数据结构看起来很正常,方便在表格视图中呈现。相应的 Mustache 模板可能如下所示:

<table>
{{#result}}
  <tr>
    <td>first: {{first}}</td>
    <td>second: {{second}}</td>
    <td>third: {{third}}</td>
  </tr>
{{/result}}
</table>

查看 Mustache 中有关 collectons 的文档。