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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745630148a4637056.html
评论列表(0条)