为什么我的模型挂钩没有收到任何参数?

Why doesn't my model hook receive no param?

免责声明:主要新手警告!

我已经按照 this 教程成功设置了 Rails backend/Ember front-end 项目。

我的路由器是

import Ember from 'ember';
import config from './config/environment';

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.resource('contacts', function() {
    this.resource('contact', { path: '/:contact_id' });
  });
});

export default Router;

现在我想设置根据联系人的姓氏仅查找某些联系人的可能性,所以我遵循了 official docs for specifying query params

我修改了我的 app/routes/contacts/index.js 路线,现在它看起来像这样:

import Ember from 'ember';

export default Ember.Route.extend({
  queryParams: {
    lastName: {
      refreshModel: true
    }
  },
  model: function(params) {
    return this.store.findQuery('contact', params);
  }
});

app/controllers/contacts.js

import Ember from 'ember';

export default Ember.ArrayController.extend({

  queryParams: ['lastName'],
  lastName: null,

});

不幸的是,即使我在浏览器中指定了查询参数,params 也没有填写。更准确地说,params 对象看起来像这样:

其中似乎没有任何我感兴趣的内容。

然而,查询参数信息 以某种方式传播到视图,所以我感到有点困惑。如何在我的路线中为模型挂钩填充 params

好像this might be a bug。一个简单的解决方法是通过可选的转换参数访问查询参数:

import Ember from 'ember';

export default Ember.Route.extend({
  queryParams: {
    lastName: {
      refreshModel: true
    }
  },
  model: function(params, transition) {
    return this.store.findQuery('contact', transition.queryParams);
  }
});