我有以下路线为特定日期范围运行报告:
export default Ember.Route.extend({
model: function(params){
return this.store.query('report' {
"report":"my_report",
"from":params.startDate,
"to":params.endDate
});
},
setupController: function(controller, model) {
this._super(controller, model);
// change format model and save it in rows
controller.set('model', rows);
}
});
现在,我的控制器如下:
export default Ember.Controller.extend({
queryParams:["startDate","endDate"],
actions:{
processReport:function(from,to){
this.transitionToRoute('reports',{
queryParams :{
"startDate":from,
"endDate":to,
"refreshModel": true
}
});
}
},
to:"",
from:""
});
模板如下:
From {{bootstrap-datepicker value=to}}
To {{bootstrap-datepicker value=from}}
<button {{action "processReport" from to}}>Process Report</button>
因此,当我点击按钮时,网址已更改,控制台显示:
Attempting transition to reports ember.debug.js:52602
Transitioned into 'reports' ember.debug.js:27426
但页面保持不变。如何完全转换到页面?
答案 0 :(得分:1)
您应该在您的路线中添加queryParams配置以进行完全转换
export default Ember.Route.extend({
queryParams: {
startDate: {
refreshModel: true
},
endDate: {
refreshModel: true
}
},
...
在控制器上,您只需要更新值&#34; startDate&#34;和&#34; endDate&#34;在自定义操作中:
Export default Ember.Controller.extend({
queryParams:["startDate","endDate"],
actions:{
processReport:function(){
this.set('startDate', this.get('from'));
this.set('endDate', this.get('to'));
}
},
to:"",
from:""
});
这已在指南中解释:
https://guides.emberjs.com/v2.11.0/routing/query-params/#toc_opting-into-a-full-transition
答案 1 :(得分:0)
我通过阅读以下链接中查询参数的更新API来自行解决:
not()