0

可能重复:
如何从 handlebarsjs 访问这个 json 对象

我有这个 json 文件:

[{         
     "id" : 9,
     "name" : "Name1",
     "address" : "address1",
     "city" : "city1",
     "state" : "KS",
     "zip" : "11111",
     "country" : "USA",
     "fax" : "111111",
     "phone" : "1111111",
     "website" : "",
     "account" : "11111",
     "contacts" : []
 }, 
 {
     "id" : 12,
     "name" : "Name2",
     "address" : "address2",
     "city" : "city2",
     "state" : "NJ",
     "zip" : "11111",
     "country" : "USA",
     "fax" : "",
     "phone" : "1111",
     "website" : "",
     "account" : "11111",
     "contacts" : [ {
         "firstName" : "name",
         "lastName" : "lastname",
         "title" : "rep",
         "phone" : "3333",
         "email" : "33333"
     } ]
} ]

我可以访问这些属性

<td>{{:name}}</td>
<td>{{:phone}}</td>
<td>{{:city}}</td>

但是如何contacts.firstName从模板访问?

4

1 回答 1

0

您的联系人是一个数组。因此,如果您想要第一个,请执行以下操作:

{{:contacts[0].firstName}}

否则,您需要使用 for 标记进行循环。

于 2012-07-21T02:06:18.590 回答