我正在尝试使用queryParams
来更新和刷新模型。我已将操作设置为使用 route-action
,因为触发该操作的更改事件位于组件内。我已安装 ember-route-action-helper
并且更改事件正常工作,但 transitionTo
未更新。
在filter-list.hbs
<input type="checkbox"
class="filter-checkbox inp-{{value.filterValueId}}"
value="{{value.filterValueId}}"
onchange={{route-action "updateQuery" value.filterValueId list.filterId}}>
在routes/results.js
export default Ember.Route.extend({
queryParams: {
status: {
refreshModel:true
},
owner: {
refreshModel:true
}
},
params: null,
model(params) {
this.set('params', params);
return Ember.RSVP.hash({
result: this.store.query('result', params),
filter: this.store.findAll('filter'),
params: params,
});
},
setupController(controller, model) {
this._super(...arguments);
controller.set('result', model.result);
controller.set('filter', model.filter);
controller.set('params', model.params);
},
actions: {
newParams(data){
console.log("Received", data);
},
updateQuery: function() {
//I make a URL string here from multiple checkboxes
//and parse the URL string as a JSON object which is
//modeled the same as a normal queryParameter
let newParams = JSON.parse('{"' + decodeURI(urlString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
console.log(newParams);
this.transitionTo({queryParams: {newParams}});
}
}
因此,我首先从 URL 中提取 params
并将其发送下来以获取结果,并填充过滤器列表(带有过滤器名称的复选框列表)。每次我单击过滤器时,如果它发现复选框已更改,它就会使用 route-action
触发路由下的 updateQuery
操作。
操作运行(并且我在控制台中得到了正确的 newParams
输出。不起作用的行是 this.transitionT()
。转换没有执行任何操作不管怎样。它没有更新模型,也没有改变 URL,什么都没有。
我错过了什么?
最佳答案
对于任何想知道的人,我已经弄清楚了。
现在,我正在将 {queryParams: {newParams}}
发送到 transitionTo
函数。但这是将 newParams
转换为一个键,其中它所保存的对象就是值,而不是使用 newParams
作为完整对象。
我已将其更改为 {queryParams: newParams}
,因此现在它使用该变量作为对象,而不是键。
this.transitionTo({queryParams: newParams});
关于javascript - EmbertransitionToqueryParams 不更新模型或 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50684041/