1
我有一個自定義API,它沒有格式化以便與Ember Data一起使用。我無法從我的api中獲取嵌套數組屬性的值。在HTMLBars中訪問數組中的索引項目
API響應:
{
"data": [
{
"id": 6,
"name": "Company Name",
"links": [
{
"rel": "self",
"uri": "/address-book/company-name"
}
],
"details": {
"data": {
"website_url": "http://website.com/",
"development_website_url": "http://dev_website.com",
"primary_phone": 9543333333,
"primary_email": "[email protected]"
}
}
},
{
"id": 3,
"name": "Company Name",
"links": [
{
"rel": "self",
"uri": "/address-book/company-name"
}
],
"details": {
"data": {
"website_url": "http://website.com/",
"development_website_url": "http://dev_website.com",
"primary_phone": 9543333333,
"primary_email": "[email protected]"
}
}
}
]
}
我試圖讓這裏顯示的鏈接是我的車把:
{{#each m in model}}
<tr>
<td>
<a href="{{m.links.uri}}">{{m.name}}</a>
</td>
</tr>
{{/each}}
現在鏈接URI僅僅是空白。如果我將其更改爲只返回{object object}的{{m.links}}
。我也嘗試{{m.links[0].uri}}
只是爲了看看這是否會工作,但沒有好處。
這是我的路由器和適配器。
export default Ember.Route.extend({
model: function(){
var adapter = AddressBookAdapter.create();
var companies = adapter.findAll();
return companies;
}
});
適配器:
export default Ember.Object.extend({
findAll: function(){
return ajax('http://localhost:8000/api/v1/address-book/companies?includes=details')
.then(function(response){
return response.data;
});
}
});
我怎樣才能獲得這些屬性的值?我覺得這很容易,我只是沒有得到它。
我不是灰燼的人,但不應該」它是更像這個... https://gist.github.com/jrgleason/ec1725d153374f317520也見http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-異步調用 – Jackie
@Jackie我不知道這有什麼幫助。 – ThreeAccents
您正在使用'ember-data'? – steveax