gpt4 book ai didi

ember.js - 处理路线时出错,工厂未定义

转载 作者:行者123 更新时间:2023-12-02 06:09:11 26 4
gpt4 key购买 nike

我正在尝试通过RESTAdapter来获取数据(遵循教程),但遇到了我不理解的错误。
"Error while processing route: players.index" "factory is undefined" "Store<.modelFor@http://localhost:4200/assets/vendor.js:74981:1
有人知道我缺少什么吗?我需要安装加载项吗?

路线/玩家/index.js

import Ember from 'ember';

export default Ember.Route.extend({
model: function() {
return this.store.find('player');
}
});

模型/player.js
import DS from 'ember-data';

export default DS.Model.extend({
finalScore: DS.attr('number'),
name: DS.attr('string'),
heightFormatted: DS.attr('string'),
heightCm: DS.attr('number'),
weightLb: DS.attr('number'),
weightKg: DS.attr('string'),
birthplace: DS.attr('string'),
birthdate: DS.attr('string'),
neoId: DS.attr('number'),
position: DS.attr('string'),
number: DS.attr('string'),
faults: DS.attr('number'),
stats: DS.belongsTo('stat')
});

models / stat.js
import DS from 'ember-data';

export default DS.Model.extend({
points: DS.attr('number'),
assits: DS.attr('number'),
defr: DS.attr('number'),
ofr: DS.attr('number'),
steals: DS.attr('number'),
blocks: DS.attr('number'),
turnovers: DS.attr('number'),
fta: DS.attr('number'),
ftm: DS.attr('number'),
fga: DS.attr('number'),
fgm: DS.attr('number'),
lsa: DS.attr('number'),
lsm: DS.attr('number'),
minutes: DS.attr('number'),
isStarter: DS.attr('boolean'),
gamesPlayed: DS.attr('number'),

player: DS.belongsTo('player')
});

适配器/application.js
import DS from 'ember-data';

export default DS.RESTAdapter.extend({
host: 'http://localhost:3000',
namespace: 'api'
});

JSON
{
"players": [
{
"neo_id": 3264,
"name": "Jeff Green",
"height_cm": 205,
"height_formatted": "6'9\"",
"weight_lb": 235,
"weight_kg": "106.8",
"position": "PF",
"number": "8",
"birthplace": "Cheverly, Maryland, USA",
"birthdate": "523843200",
"stats": {
"final_score": 344,
"games_played": 16,
"minutes": 34.5,
"points": 19,
"assits": 1.75,
"defr": 3.75,
"ofr": 1,
"steals": 0.94,
"blocks": 0.69,
"turnovers": 1.56,
"faults": 1.94,
"neo_id": 3264
}
},
{
"neo_id": 3265,
"name": "Erik Murphy",
"height_cm": 208,
"height_formatted": "6'10\"",
"weight_lb": 230,
"weight_kg": "104.6",
"position": "PF",
"number": "-1",
"birthplace": "Lyon, France",
"birthdate": "656899200",
"stats": {}
}
]
}

最佳答案

我无法重现您的确切错误,但是通过与您共享的内容一起工作,我可以通过进行这些更改来使其正常工作。如果您的代码有不同之处,请发表评论,我会看一下。

serializers / application.js

由于您使用的是自定义主键(neo_id而不是id),因此可以在此处进行更改,并指出stats记录已嵌入players数据中:

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs : {
stats: { embedded: 'always' }
},
primaryKey : 'neo_id'
});

Working JSBin

关于ember.js - 处理路线时出错,工厂未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27295725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com