因此,该应用程序所有路线的模型设置如下:
model(params) {
let config = this.get('store').findRecord(params.config_type, params.config_id);
let c = Ember.RSVP.hash({config});
console.log('aa');
console.log(c);
let devices = this.get('store').findAllOfType('device', ENV.CFG_TYPE[params.config_type]);
let licenses = this.get('store').findAll('license');
return Ember.RSVP.hash({
configType: params.config_type,
config: config,
devices: devices,
licenses: licenses
});
},
我需要更改设备查询以使用第一个查询返回的配置中保存的辅助条件。唯一的问题是这尚未解决并且其中没有数据。
当我注销 c 时,我看到 _results 属性最初未定义,然后当我展开它时,它显示配置对象。
我意识到这是因为 promise 尚未解决,并且会在未来某个时间解决,但我需要这些数据来获取正确的设备。我不想将它们作为查询参数传递,因为它们是我需要的两个单独的数据。
我想我可以在配置行上执行 .then() 并返回其中的 Ember.RSVP.hash 但这会将其返回到 model() 并且我不确定如何从那里返回它,或者如果它甚至会从那里返回,或者配置现在等于 RSVP 哈希而不是配置 promise /对象。
我的选择是:
找到一种方法以某种方式将其从模型中已具有相同配置对象的一条路由传递到此路由,而不使用查询参数
以某种方式在第一个查询的回调中设置整个模型(findRecord())
完全不知道如何做到这一点。
最佳答案
我试过了,请看看这个,
model(params) {
return this.get('store').findRecord(params.config_type, params.config_id).then(resultantConfig => {
//resultantConfig use this to get exact property which is going to be used for the below queries.
return Ember.RSVP.hash({
configType: params.config_type,
config: resultantConfig,
//findAllOfType - i am not heard of this method, i guess it would query, as you need to set condition.
devices: this.get('store').query('device', {configType:resultantConfig.config_type}),
licenses: this.get('store').findAll('license')
});
});
}
关于javascript - Ember 需要模型中一个 Promise 的数据用于 model() 中的另一查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44202946/