2014-04-03 30 views
2

我在Ember.js App中創建視圖,並且想要顯示JSON object中的某些值。在我的路線的模型鉤子中,我打電話給API endpoint,返回JSON object,其中包含兩個arrays如何訪問句柄模板中的JSON屬性值

我想我可以簡單地參考我的handlebars template中的JSON properties,它會輸出該值,但這不符合預期。取而代之的是,它看起來像我得到的JSON對象的字符串描述:在我的車把模板

[object Object],[object Object] 

我如何可以訪問JSON object's property values

路線:

var CompareRoute = Ember.Route.extend({ 
    model: function(params) { 
    return $.getJSON('/api/compare_segments?' + params.ids).then(function(payload) { 
     return payload; 
    }); 
    }, 

}); 

export default CompareRoute; 

把手模板:

JSON
{{item_summaries}} 

API endpoint(截)格式返回:

{ 
    "item_summaries": [ 
    { 
     "item_desc": "example", 
     "item_id": 1, 
     "item_summary": [ 
     { 
      "children": [ 
       { 
        "measure": "% users clicking", 
        "value": null 
       } 
    ... 

    { 
     "item_desc": "example2", 
     "item_id": 2, 
     "item_summary": [ 
     { 
      "children": [ 
      { 
       "children": [ 
    ... 

} 

回答

0

你應該使用每個幫助,因爲你有需要打印的集合。

{{#each item_summaries}} 
    //access the properties of a single item_summary and write your html code 
{{/each}} 
+0

謝謝Hrishi,那就是我一直在尋找 – dagarre