简体   繁体   中英

Javascript, mustache.js, how to

I am using mustache.js, to put my page together, and on an event i am catching a json object, which I save in a variable, the code looks like this:

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

I cant figure out what mustache structure to use on the template to show the data in a table. It seems the array is irregular shaped, I want to put it into a table. Any ideas? THX.

The data structure looks quite normal and convenient for rendering in tabular view. Corresponding Mustache template could look something like this then:

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

Check the documentation about collectons in Mustache.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM