使用ember模型插入图像

时间:2014-04-22 14:23:17

标签: javascript ember.js

我有一个ember应用程序,我通过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";

1 个答案:

答案 0 :(得分:1)

您的模型定义似乎缺少avatar_url属性。

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