2017-05-26 55 views
2

所以对于这个应用程序模型的所有路由设置是这样的:灰烬需要从一个承诺数据模型在模型()的另一个查询

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

我需要改变设备的查询使用在第一个查询返回的config中保存的第二个标准。唯一的问题是这个问题没有解决,也没有数据。

当我注销c时,我最初看不到_results属性,那么当我展开它时,它会显示配置对象。

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

我在想我可以在配置行上执行.then()并返回Ember.RSVP.hash,但那会将它返回到model(),我不知道如何从那里返回它,或者如果它甚至会从那里返回,或者如果配置现在等于RSVP散列而不是配置承诺/对象。

我的选择是:

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

  2. 设置在第一个查询回调以某种方式()的findRecord(一个)整个模型

关于如何做到这一点无论哪种方式完全一无所知。

回答

2

我试过了,请看看这个,

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