Ember:TypeError:internalModel.getRecord不是函数

时间:2015-09-25 11:04:37

标签: javascript ember.js

我在组件内部,尝试在操作中添加新创建的实体:

var stakeholding = this.get('store').createRecord('stakeholding', {[...]});

var allCarings = this.get('allCarings');
allCarings.insertAt(0, stakeholding);

但我收到此错误消息:

TypeError: internalModel.getRecord is not a function

allCarings在页面启动时初始化,如下所示:在组件内:

this.store.find('stakeholding', {[...]}).then(function(data){   
    _this.set('allCarings', data);
});

我应该如何正确地将我的实体添加到数组中?

2 个答案:

答案 0 :(得分:0)

您应该使用allCarings将记录添加到pushObject数组:

var stakeholding = this.get('store').createRecord('stakeholding', {[...]});

var allCarings = this.get('allCarings');
allCarings.pushObject(stakeholding);

答案 1 :(得分:-1)

我是Ember的新手,并不确切知道为什么,但这对我有用:

allCarings.insertAt(0, stakeholding._internalModel);