我使用ember-cli@3.27.0 , ember-data@3.27.1
有一个工作班次。js模型
import DS from 'ember-data';
export default DS.Model.extend({
date: DS.attr(),
timestart: DS.attr(),
timeend: DS.attr(),
house: DS.belongsTo('house'),
responsible: DS.belongsTo('employee'),
employeeOnWorkshift: DS.hasMany('employee-on-workshift'),
});
有员工轮班。js模型
import DS from 'ember-data';
export default DS.Model.extend({
workshift: DS.belongsTo('workshift'),
account: DS.belongsTo('account'),
employee: DS.belongsTo('employee'),
});
和员工。js模型
import DS from 'ember-data';
export default DS.Model.extend({
fio: DS.attr(),
age: DS.attr(),
phone: DS.attr(),
datebirth: DS.attr(),
telegram: DS.attr(),
user: DS.belongsTo('people'),
employeeOnWorkshift: DS.hasMany('employee-on-workshift'),
});
在此过程中,我将所有工作班次及其关联的employeeOnWorkshift数据作为数组卸载。
import Route from './base-route';
import RSVP from 'rsvp';
export default Route.extend({
model(params) {
return this.store.findRecord('workshift', params.id);
},
afterModel(models) {
models.get('employeeOnWorkshift').forEach((employeeOnWorkshift) => {
employeeOnWorkshift.get('employee');
employeeOnWorkshift.get('employee.user');
})
}
});
是的,我知道为每个列表项加载额外的模型是一个错误的决定,但我的目标是找出数据不显示的原因。
在模板中,我只是浏览模型列表并尝试获得一名员工。fio,但数据为空
{{#each model.employeeOnWorkshift as |employeeOnWorkshift|}}
{{employeeOnWorkshift.employee.fio}}
{{/each}}
虽然在网络浏览器中,我可以看到employeeOnWorkshift列表中每个员工的数据是如何加载的:Requests to the backend
我在控制台中检查了e型员工。Proxy对象在那里返回,据我所知,如果isPending=false和isSettled=true,内容参数将使用Model对象填充,但即使在接收到数据后,也不会发生这种情况。
Proxy {isFulfilled: false, isRejected: false, content: null, _belongsToState: {…}, _super: ƒ, …}
[[Handler]]: Object
[[Target]]: Class
content: null
isFulfilled: false
isRejected: false
_belongsToState: {key: 'employee', store: Store, originatingInternalModel: InternalModel, modelName: 'employee'}
_super: ƒ ()
Symbol(INIT_FACTORY): undefined
Symbol(OWNER): undefined
isPending: true
isSettled: false
isTruthy: false
meta: (...)
promise: (...)
isDestroyed: (...)
isDestroying: (...)
_debugContainerKey: (...)
[[Prototype]]: Class
[[IsRevoked]]: false
请告诉我我做错了什么,为什么员工没有这种形式的拐杖就不能被卸载:
models.get('employeeOnWorkshift').forEach((model) => {
model.employee.then(function (employee) {
model.employee = employee;
});
});
1条答案
按热度按时间huus2vyu1#
afterModel钩子需要等待相关记录的获取,否则在最初呈现时它们将不存在。