我有一個奇怪的問題與燼js,當我推動一個對象的模型。這裏是我的代碼:pushobject不是一個函數emberjs
// Environment.js
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: true,
Array: true,
}
Route.js
model() {
return Ember.RSVP.hash({
newCollection: this.get('store').createRecord('collection'),
book1: this.get('store').createRecord('book'),
book2: this.get('store').createRecord('book')
})
}
控制器
actions:{
addCollection(model) {
model.newCollection.pushObject(model.book1);
model.newCollection.pushObject(model.book2);
},
}
現在,我不知道是什麼問題,但我試圖把書模型進入集合,但是,我得到一個問題,因爲控制檯日誌表明,pushObject不是一個函數。我已經更新了我的Environment.js,正如其他問題所建議的,但這仍然是一個問題。
集模型
// collection Model
export default DS.Model.extend({
name: DS.attr('string'),
city: DS.attr('string'),
books: DS.hasMany('book', { async: true })
});
書模型
//book Model
export default DS.Model.extend({
title: DS.attr('string'),
description: DS.attr('string'),
collection: DS.belongsTo('collection', {async: true})
});
請出示您的模型 – Lux
@Lux模型已被添加到這個問題 – jsg