我有以下类:
App.Entity = Ember.Object.extend({
id: null,
name : null,
});
我有以下控制器:
App.HomeController = Ember.ObjectController.extend({
entities: null,
init:function(){
var myArray = [];
var a = App.Entity.create();
a.set('id',1);
a.set('name','A');
var b = App.Entity.create();
b.set('id'2);
b.set('name','B');
//and I add another entities dynamycally
myArray.push(a);
myArray.push(b);
console.log( 'isArray: '+ Ember.isArray(myArray) ); //I get true
this.set('entities', myArray );
}
});
问题出现在我尝试迭代并在视图上呈现内容时:
<script type="text/x-handlebars" data-template-name="home" ></script>
我收到了以下错误信息:
Assertion Failed: The value that #each loops over must be an Array. You passed <App.Entity:ember425>,<App.Entity:ember426>,...
如何修复?
this.set('entities', [myArray] );
。 - Andreithis.set('entities', [myArray] );
,那么我将在entities的第一个位置放置一个数组(myArray
),不会将myArray
转换为EmberArray(或者其他Ember可以迭代的东西)。然后当我渲染我的视图时,我得到了<App.Entity:ember423>,<App.Entity:ember424>,....
。如何呈现每个值的内容,{{ this.WHAT??}}
? - Cristian