![](/img/trans.png)
[英]Ember.js with EmberFire Object - How to use with array attributes?
[英]How to access array like object/values in ember.js
我需要一些帮助才能正确显示我的数据。 如果我尝试访问缩略图路径,则应用程序将引发以下错误:
断言失败:属性必须是数字,字符串或布尔值,而不是[http://example.com/imgage/example_thumb.jpg]
如何消除此错误并正确显示图像?
DEBUG: -------------------------------
DEBUG: Ember.VERSION : 1.0.0
DEBUG: Handlebars.VERSION : 1.0.0
DEBUG: jQuery.VERSION : 2.0.3
DEBUG: -------------------------------
// models/collection_model.js
App.Collection = DS.Model.extend({
title: DS.attr('string'),
assets: DS.attr('object')
});
// datastore.js
App.Collection.FIXTURES = [
{
"id": 1,
"title": "Lorem ipsum",
"assets": {
"thumb": ['http://example.com/imgage/example_thumb.jpg'],
"thumb_large": ['http://example.com/imgage/example.jpg']
}
},
{
"id": 2,
"title": "Losabim",
"assets": {
"thumb": ['http://example.com/imgage/example_thumb.jpg'],
"thumb_large": ['http://example.com/imgage/example.jpg']
}
}
];
// templates/collection.handlebar
<script type="text/x-handlebars" data-template-name="collections">
<h2>Collections</h2>
<ul>
{{#each collection in controller}}
<li>
{{collection.title}}
<img {{bind-attr src=collection.assets.thumb }}/>
</li>
{{/each}}
</ul>
</script>
灰烬具有firstObject
和lastObject
:
<img {{bind-attr src=collection.assets.thumb.firstObject }}/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.