在以下 json 文件中:
{
"students":[
{
"timestamp": "1,45198E+12",
"personnummer": 1234567891011,
"fornavn": "Some name"
}
]
}
我正在使用 Handlebars 根据这些信息制作表格,如何将“timestamp”、“personnummer”等获取到 <th>
标记中。
我已经尝试过:
索引:{{@index}} Value = {{this}}
和: key :{{@key}} Value = {{this}}
但我只是得到:“索引:0值= [对象对象]”
有人可以解释一下吗?
最佳答案
如果
var obj = {
"students":[
{
"timestamp": "1,45198E+12",
"personnummer": 1234567891011,
"fornavn": "Some name"
}
]
}
那么你的 Handlebars 应该看起来像一个循环:
<ul class="student_list">
{{#each students.[0]}}
<li>{{@key}}</li>
{{/each}}
</ul>
关于javascript - 如何在带有 Handlebars 的 json 文件中获取对象键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36833449/