Javascript 如何访问ember.js中类似数组的对象/值
我需要一些帮助来正确显示我的数据。如果我尝试访问缩略图路径,应用程序将抛出以下错误: 断言失败:属性必须是数字、字符串或布尔值,而不是 [http://example.com/imgage/example_thumb.jpg] 如何消除此错误并正确显示图像Javascript 如何访问ember.js中类似数组的对象/值,javascript,ember.js,Javascript,Ember.js,我需要一些帮助来正确显示我的数据。如果我尝试访问缩略图路径,应用程序将抛出以下错误: 断言失败:属性必须是数字、字符串或布尔值,而不是 [http://example.com/imgage/example_thumb.jpg] 如何消除此错误并正确显示图像 DEBUG: ------------------------------- DEBUG: Ember.VERSION : 1.0.0 DEBUG: Handlebars.VERSION : 1.0.0 DEBUG: jQuery.VERSI
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>
调试:-------------------------------
调试:Ember.VERSION:1.0.0
调试:handlebar.VERSION:1.0.0
调试:jQuery.VERSION:2.0.3
调试:------------------------------------
//模型/集合_model.js
App.Collection=DS.Model.extend({
标题:DS.attr('string'),
资产:DS.attr('object')
});
//datastore.js
App.Collection.FIXTURES=[
{
“id”:1,
“标题”:“Lorem ipsum”,
“资产”:{
“拇指”:['http://example.com/imgage/example_thumb.jpg'],
“拇指大”:['http://example.com/imgage/example.jpg']
}
},
{
“id”:2,
“标题”:“Losabim”,
“资产”:{
“拇指”:['http://example.com/imgage/example_thumb.jpg'],
“拇指大”:['http://example.com/imgage/example.jpg']
}
}
];
//模板/collection.handlebar
收藏
-
{{{#控制器中的每个集合}
- {{collection.title} {{/每个}}
余烬拥有
第一个对象
和最后一个对象
:
<img {{bind-attr src=collection.assets.thumb.firstObject }}/>
不要问为什么api会返回数组……谢谢你!记录如下: