免责声明:主要新手警告!
我已经按照 this 成功设置了 Rails 后端/Ember 前端项目教程。
我的路由器是
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
对象如下所示:
其中似乎没有包含任何我感兴趣的内容。
然而,查询参数信息以某种方式传播到 View ,所以我感到有点困惑。如何为我的 route 的模型 Hook 填充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);
}
});
关于javascript - 为什么我的模型钩子(Hook)没有收到参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28870860/