Ember 需要模型中一个承诺的数据用于模型中的另一个查询()

Ember Need data from one promise in the model for another query in model()

所以这个应用程序的所有路线的模型是这样设置的:

  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
    });
  },

我需要更改设备查询以使用次要条件,该条件保存在由第一个查询 return 编辑的配置中。唯一的问题是这个没有解决,里面没有数据。

当我注销 c 时,我看到 _results 最初未定义 属性,然后当我展开它时,它显示了配置对象。

我意识到这是因为承诺尚未解决,并且会在未来某个时间解决,但我需要该数据才能获得正确的设备。我不想将它们作为查询参数传递,因为这是我需要的两个独立数据。

我想我可以在配置行上做 .then() 并且 return 那里的 Ember.RSVP.hash 但是那会 return 它到 model() 而我不是确定我如何从那里 return 它,或者它是否甚至 return 从那里,或者如果配置现在等于 RSVP 哈希而不是配置 promise/object.

我的选择是:

  1. 找到一种方法,以某种方式将它从一个路由(模型中已有相同的配置对象)传递到这个路由,而不使用查询参数

  2. 以某种方式在第一个查询的回调中设置整个模型(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')
            });
        });
    }