我在我的Ember应用程序中为两个模型引入了一对多关联,我得到了这些相当神秘的错误:
[09:01:20.450] TypeError: type is undefined @ http://emberjs.com.s3.amazonaws.com/getting-started/ember-data.js:2284
[09:01:20.444] DEPRECATION: Action handlers contained in an `events` object are deprecated in favor of putting them in an `actions` object (error on <Ember.Route:ember362>)
trigger@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:29641
handleError@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:29903
invokeCallback@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:8055
Promise.prototype.then/<@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:8109
EventTarget.trigger@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:7878
reject/<@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:8180
DeferredActionQueues.prototype.flush@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:5459
Backburner.prototype.end@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:5545
Backburner.prototype.run@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:5584
executeTimers@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:5807
Backburner.prototype.setTimeout/laterTimer<@file:///home/zen/ember-project/js/libs/ember-1.0.0.js:5666
[09:01:20.444] Error while loading route: (new TypeError("type is undefined", "http://emberjs.com.s3.amazonaws.com/getting-started/ember-data.js", 2284))
我不确定我是否应该在DS.belongsTo('modelName')
中大写,降低版本或降低模型名称,但是当它们被驼峰时我得到这个错误,其他套管得到'模型无法找到'错误所以我认为这是最好的错误。
我的模型和夹具数据:
// Models
App.ServiceProvider = DS.Model.extend({
name: DS.attr('string'),
email: DS.attr('string'),
customers: DS.hasMany('customer')
});
App.Customer = DS.Model.extend({
serviceprovider: DS.belongsTo('serviceProvider'),
firstname: DS.attr('string'),
lastname: DS.attr('string'),
email: DS.attr('string')
});
// Fixtures
App.ServiceProvider.FIXTURES = [
{
id: 1,
name : "Some Org.",
email : "admin@someorg.com.au",
customers : [1, 2]
},
{
id: 2,
name : "Some Co.",
email : "admin@someco.com.au",
customers : [3, 4]
}
];
App.Customer.FIXTURES = [
{
id: 1,
firstname : "John",
lastname : "Smith",
email : "admin@someorg.com.au",
serviceprovider : [1]
},
{
id: 2,
firstname : "Jane",
lastname : "Smith",
email : "admin@someco.com.au",
serviceprovider : [1]
},
{
id: 3,
firstname : "Jerry",
lastname : "Smith",
email : "admin@someco.com.au",
serviceprovider : [2]
},
{
id: 4,
firstname : "Janet",
lastname : "Smith",
email : "admin@someco.com.au",
serviceprovider : [2]
}
];
我对Ember很新,任何见解都值得赞赏。
答案 0 :(得分:0)
我只是想通了,问题是使用数组作为一对一关系的id。
这是有问题的装置
App.Customer.FIXTURES = [
{
id: 1,
firstname : "John",
lastname : "Smith",
email : "admin@someorg.com.au",
serviceprovider : [1]
}
]
这是工作中的
App.Customer.FIXTURES = [
{
id: 1,
firstname : "John",
lastname : "Smith",
email : "admin@someorg.com.au",
serviceprovider : 1
}
]