Ember.js:绑定查询参数以选择异步加载内容的菜单
我有一个带有国家/地区筛选器的用户搜索表单。选择菜单(下拉菜单)中的国家/地区将异步加载余烬数据。所选国家/地区绑定到查询参数:Ember.js:绑定查询参数以选择异步加载内容的菜单,ember.js,Ember.js,我有一个带有国家/地区筛选器的用户搜索表单。选择菜单(下拉菜单)中的国家/地区将异步加载余烬数据。所选国家/地区绑定到查询参数: https://myapp.com/users?country=123 工作:当用户从选择菜单中选择国家时,URL将更新并包含国家id 不工作:当用户浏览回包含一个国家作为查询参数的URL时,选择菜单确实包含所有国家,但是没有选择正确的国家+查询参数变得未定义:/users?country=未定义 模板: {{view "select" cont
https://myapp.com/users?country=123
- 工作:当用户从选择菜单中选择国家时,URL将更新并包含国家id
- 不工作:当用户浏览回包含一个国家作为查询参数的URL时,选择菜单确实包含所有国家,但是没有选择正确的国家+查询参数变得未定义:
/users?country=未定义
{{view "select"
content=countries
value=country
optionLabelPath="content.name"
optionValuePath="content.id"}}
控制器:
export default Ember.Controller.extend({
countries: Ember.computed(function () {
return this.store.find('country');
}),
country: null,
queryParams: ['country'],
});
路线:
export default Ember.Route.extend({
model: function (params) {
return this.store.find('user', params);
}
});
有什么建议吗?谢谢!:) 我离得太近了!似乎我加载国家的时间太晚了,因此select没有与查询参数匹配的数据 我刚刚在
模型中移动了加载国家的代码
挂钩:
model: function (params) {
return Ember.RSVP.hash({
users: this.store.find('user', params),
// Pre-load the countries so the queryParams binding
// with the select menu work properly
countries: this.store.find('countries')
});
},
现在看来很明显,我已经找到了解决办法