admin管理员组文章数量:1435859
I found a jsbin that illustrates my problem. .
That last link, where there are no explicit query-params set on the link-to, it uses the current sticky query param value on the controller. It there a way to turn this sticky feature off? Would doing so break other scenarios?
My current solution is to null out query params on every route I want cleared:
export default Ember.Route.extend({
deactivate: function() {
var controller = this.controllerFor(this.get('controllerName'));
var queryParams = controller.get('queryParams');
for (var i = 0; i < queryParams.length; i++)
controller.set(queryParams[i], null);
}
});
This works but it seems like there should be an easier way.
I should note that doing something like {{#link-to 'route' (query-params val=null)}}{{/link-to}}
for every route is not an option because I have some reusable code where the route is a variable, so I won't know the query params I have to null out.
Edit:
Here is the proper way to do it, in case the doc's from the answer change:
export default Ember.Route.extend({
resetController: function(controller, isExiting) {
if (isExiting) {
var queryParams = controller.get('queryParams');
for (var i = 0; i < queryParams.length; i++)
controller.set(queryParams[i], null);
}
}
});
Edit 2:
It's now very easy to do this via this addon . It also resets to the original values, not just nulling out values.
I found a jsbin that illustrates my problem. http://emberjs.jsbin./ucanam/2708.
That last link, where there are no explicit query-params set on the link-to, it uses the current sticky query param value on the controller. It there a way to turn this sticky feature off? Would doing so break other scenarios?
My current solution is to null out query params on every route I want cleared:
export default Ember.Route.extend({
deactivate: function() {
var controller = this.controllerFor(this.get('controllerName'));
var queryParams = controller.get('queryParams');
for (var i = 0; i < queryParams.length; i++)
controller.set(queryParams[i], null);
}
});
This works but it seems like there should be an easier way.
I should note that doing something like {{#link-to 'route' (query-params val=null)}}{{/link-to}}
for every route is not an option because I have some reusable code where the route is a variable, so I won't know the query params I have to null out.
Edit:
Here is the proper way to do it, in case the doc's from the answer change:
export default Ember.Route.extend({
resetController: function(controller, isExiting) {
if (isExiting) {
var queryParams = controller.get('queryParams');
for (var i = 0; i < queryParams.length; i++)
controller.set(queryParams[i], null);
}
}
});
Edit 2:
It's now very easy to do this via this addon https://github./kellyselden/ember-query-params-reset. It also resets to the original values, not just nulling out values.
Share Improve this question edited Apr 8, 2016 at 18:29 Kelly Selden asked Oct 21, 2014 at 13:31 Kelly SeldenKelly Selden 1,2761 gold badge11 silver badges21 bronze badges1 Answer
Reset to default 3It gives you two options for how to handle this in the guides: https://guides.emberjs./release/routing/query-params/#toc_sticky-query-param-values
Looks like option #2 is pretty close to what you are doing:
use the Route.resetController hook to set query param values back to their defaults before exiting the route or changing the route's model.
本文标签: javascriptTurn off sticky query params in EmberjsStack Overflow
版权声明:本文标题:javascript - Turn off sticky query params in Ember.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745630147a2667221.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论