2017-01-31 19 views
0

我有这样的JSON:Accesing JSON与车把

{ 
    { 
    "status": { 
    "success": true, 
    "error": "" 
    }, 
    "data": { 
    "hello_world": [ 
     { 
     "uid": { 
      "email": "[email protected]", 
      "id": "d3c074d8b2b24e958" 
     }, 
     "my_itm": { 
      "name": "BIg", 
      "id": "2380caa99cb426f" 
     }, 
     "id": "6747e005f23f451" 
     }, 
     { 
     "uid": { 
      "email": "[email protected]", 
      "id": "5859082d3c074d8b2b24e958" 
     }, 
     "my_itm": { 
      "name": "Dog", 
      "id": "a99cb426f" 
     }, 
     "id": "c6747e005f23f452" 
     } 
    ] 
    } 
} 

我使用的把手,我想从my_itm名称来访问。但我想这样做foreach my_itm。我怎样才能做到这一点?

这里是我试过:

{{#each hello_world.my_itm}} 
    <p>{{name}}</p> 
{{/each}} 

回答

0

更新:

假设你传递下的 'PARAMS' 名称的数据到模板:

res.render('test', {params: <your data>}) 

你可以这样做:

{{#each params.data.hello_world}} 
      {{#if my_itm}} 
        {{my_itm.name}} <br> 
      {{/if}} 
{{/each}} 

给出:

BIg 
Dog 

你有没有工作,因为程序hello_world是一个数组,而不是与您可以直接访问my_itm属性的对象,你需要遍历数组第一。

PS:你似乎还有一个额外的{在json中。