Ember.js pushobject不是一个函数
当我将一个对象推送到一个模型时,ember js有一个奇怪的问题。这是我的密码:Ember.js pushobject不是一个函数,ember.js,Ember.js,当我将一个对象推送到一个模型时,ember js有一个奇怪的问题。这是我的密码: // 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(
// 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})
});
你打错了。您正在推送到实际的模型,而不是
书籍
有许多关系:
actions: {
addCollection(model) {
model.newCollection.get('books').pushObject(model.book1);
model.newCollection.get('books').pushObject(model.book2);
},
}
你打错了。您正在推送到实际的模型,而不是书籍
有许多关系:
actions: {
addCollection(model) {
model.newCollection.get('books').pushObject(model.book1);
model.newCollection.get('books').pushObject(model.book2);
},
}
您的问题是,newCollection
是一个收集记录。
所以你应该:
model.newCollection.get('books').pushObject(model.book1);
您的问题是,newCollection
是一个收集记录。
所以你应该:
model.newCollection.get('books').pushObject(model.book1);
请出示证件models@Lux模型已添加到问题中,请出示您的models@Lux模型已添加到问题中。实际上,编号。模型
不是余烬对象。他正在返回return-Ember.RSVP.hash({…})
。对注释进行了处理。实际上没有。model
不是一个Ember对象。他正在返回return Ember.RSVP.hash({…})
。对评论进行了回复。