我有一个ember应用程序,我通过api提取数据。应用代码看起来像这样......
<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>
我什么都没得到......甚至连图像的路径都没有。
我尝试插入像这里建议的图像标记......
...但我在浏览器中没有任何操作,并且控制台中没有错误。
我错过了什么?
// 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 :(得分:1)
您的模型定义似乎缺少avatar_url
属性。
App.Shot = Ember.Model.extend({
name: Ember.attr(),
avatarUrl: Ember.attr()
});