2014-04-22 49 views
2

我有一個應用程序,我通過api提取數據。該應用程序的代碼看起來像這樣...插入帶有餘燼模型的圖像

的index.html

<ul> 
{{#each item in model}} 
    <li>{{item.name}}</li> 
{{/each}} 
</ul> 

...和API源數據是JSON和看起來像這樣...

{"shots":[{"id":1,"name":"joe1","avatar_url":"http://s3.amazonaws.com/daily_comedy_app/shots/avatars/000/000/001/original/1_985u645296.jpg?1392926501"},{"id":2,"name":"cgrim1","avatar_url":"http://s3.amazonaws.com/daily_comedy_app/shots/avatars/000/000/002/original/1_O7iwbEe.jpg?1392926554"},{"id":3,"name":"Mac","avatar_url":"http://s3.amazonaws.com/daily_comedy_app/shots/avatars/000/000/003/original/2014-03-06_12.48.16.jpg?1394146693"},{"id":4,"name":"wintas","avatar_url":"http://s3.amazonaws.com/daily_comedy_app/shots/avatars/000/000/004/original/1_O7iwbEe.jpg?1397231591"}]} 

上面的代碼在我的索引頁加載正常,但我無法添加avatar_url。當我嘗試...

<ul> 
{{#each item in model}} 
    <li>{{item.avatar_url}}</li> 
{{/each}} 
</ul> 

我什麼也沒有得到....甚至不是圖像的路徑。

我試圖插入圖像標籤就像是在這裏提出......

In Ember.js templates, how does one print out model's property that will be use by HTML like the src for image or href for link

...但我不想在瀏覽器中得到什麼,並且有在控制檯中沒有錯誤。

我錯過了什麼?

更新

//app.js

App.Shot = Ember.Model.extend({ 
    name: Ember.attr() 
}); 

App.Shot.adapter = Ember.RESTAdapter.create(); 

App.Shot.url = "myapi.com/api/v1/shots?api_key=12d2d06fb2f6a786ac75b32625cf83a1"; 

App.Shot.collectionKey = "shots"; 
+0

你可以發佈模型和控制器代碼?另外,它顯示的項目的名稱? –

+0

上面增加了型號代碼... – Lumbee

回答

1

好像你的模型定義缺乏avatar_url屬性。

App.Shot = Ember.Model.extend({ 
    name: Ember.attr(), 
    avatarUrl: Ember.attr() 
}); 
+0

熱潮!你把它釘死了...... thanx! – Lumbee