How do I change query parameters in Ember?

浪尽此生 提交于 2019-12-12 20:05:51

问题


I'm writing an action handler in route:application:

actions: {
  changeFoo(foo) {
    // I want to change the fooId queryParam to foo.get('id')
  }
}

The problem is that the only documented ways I can find to change the query params are transitionTo('some.route', someModel, { queryParams: { ... } } and the replaceWith version of the same. But I'm in route:application, so I don't know the current route's name. That means I don't know what the first argument to transitionTo would be.

Is there another way to get the URL to become ?fooId=123?


回答1:


You don't need current route name. You can just do 'transitionTo({queryParams: { foo: 123 })'. The router will apply it to the correct route.




回答2:


From controller:application you can set the query param foo like this:

import Ember from 'ember';

export default Ember.Controller.extend({
  queryParams: ['foo'],

  actions: {
    updateMyQueryParam() {
      this.set('foo', 'hello');
    }
  }
});


来源:https://stackoverflow.com/questions/35192211/how-do-i-change-query-parameters-in-ember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!