Ember.js 在ember cli应用程序中查询多个淹没的参数

Ember.js 在ember cli应用程序中查询多个淹没的参数,ember.js,ember-cli,query-parameters,Ember.js,Ember Cli,Query Parameters,我有三种型号 国家,, 城市、购物中心 路线看起来像 export default Ember.Route.extend({ model: (params) -> Ember.RSVP.hash country: @store.find('country', params); }); 模板看起来像 {{view "select" class="btn btn-default dropdown-toggle" content=model.country optionL

我有三种型号

国家,, 城市、购物中心

路线看起来像

export default Ember.Route.extend({
 model: (params) ->
   Ember.RSVP.hash country: @store.find('country', params);
});
模板看起来像

{{view "select" 
  class="btn btn-default dropdown-toggle"
  content=model.country
  optionLabelPath="content.name"
  optionValuePath="content.id"
  value=selectedCountry
  prompt="Country"
  }}
  {{view "select" 
  class="btn btn-default dropdown-toggle"
  content=currentCities
  optionLabelPath="content.name"
  optionValuePath="content.id"
  value=selectedCity
  prompt=City
  }} 
  {{view "select" 
  class="btn btn-default dropdown-toggle"
  content=currentMalls
  optionLabelPath="content.name"
  optionValuePath="content.id"
  value=value
  prompt=Mall
  }}
城市和购物中心下拉列表分别基于国家和城市选择动态生成

我的控制器里有

export default Ember.ObjectController.extend({
 queryParams: ['selectedCountry', 'selectedCity']
 selectedCountry: null,
 seletedCity: null,
 currentCities: null,
 currentMalls: null,

selectedCountryChanged: function() {
  this.set('currentCities', this.store.find('city');    
}.observes('selectedCountry')
selectedCityChanged: function() {
this.set('currentMalls', this.store.find('mall'));    
}.observes('selectedCity')
});
查询参数在第一个下拉列表中正常工作,但在第二个下拉列表中我没有得到正确的值,假设我选择country作为united states,则调用的资源为

res/v1.0/countries/unitedstates

当我选择城市时,资源看起来像

res/v1.0/countries/unitedstates/cities/chicago

当我用这些选定值复制url时。。查询参数

selectedCountry=美国&selectedCity=未定义


你能为我推荐一个解决上述问题的方法吗。基本上,在我为城市分配查询参数之前,城市也应该加载。。但是城市加载将取决于country query param

我通过更改store.find表达式并假设一个简单的api来实现这一点

路线:

model: function () {
  return this.store.find('country');
  // call looks like: api/countries
}
控制器:

 selectedCountry: null,
 selectedCity: null, 
 selectedMall: null,

 currentCities: null,
 currentMalls: null,

 getCities: Ember.observer('selectedCountry',function(){
    var params = {country: this.get('selectedCountry')};
    this.set('currentCities', this.store.findQuery('city',params));
        // call looks like: api/cities?country=US
 }),
 getMalls: Ember.observer('selectedCity',function(){
    var params = {country: this.get('selectedCountry'), city: this.get('selectedCity')};
    this.set('currentMalls', this.store.findQuery('mall',params));
        // call looks like: api/malls?country=US&city=LA
 }),

我认为国家列表的api不需要查询参数,而城市或购物中心的依赖列表将使用查询参数

请发布更多关于这个问题的信息:你的模板到底是什么样的(全部3个选项),它现在是如何工作的,以及它应该如何工作。什么是“淹没”?@torazaburo it's dropdown(),我想谢谢你的回复。我已经添加了模板的外观