Ember-data resets queryParam to default value

心已入冬 提交于 2020-01-17 02:39:10

问题


In my model, I have a queryParam status which is set to refreshModel true in my route.

queryParams: {
    status: {
        refreshModel: true
    }
}

In my controller, this param is set to 'opened' by default :

App.ConversationsController = Ember.ArrayController.extend({
    queryParams: ['status']
    status: 'opened'
});

Everytime I set this param to something else, for example 'all', Ember-data resets it to 'opened' and makes two calls instead of one to my model hook, and this behavior has been observed with breakpoints on my model hook (I don't know where it resets), one with param:opened and one with param:all. I even put an observer on it and it effectively does that.

Note that I already searched my code and there is litteraly nowhere where I set this param back to original value.

Any hints?


回答1:


You have to declare them also in your controller to be an expected param in your route

App.ConversationsController = Ember.ArrayController.extend({
    queryParams: ['status'],
    status: 'opened'
});

Ember has sticky params, as in the docs said.

By default, query param values in Ember are "sticky", in that if you make changes to a query param and then leave and re-enter the route, the new value of that query param will be preserved (rather than reset to its default). This is a particularly handy default for preserving sort/filter parameters as you navigate back and forth between routes

You can check out more here ... ember query params

You can try to reset them in your route

resetController: function (controller, isExiting, transition) {
        if (isExiting) {
          //reset controller to avoid sticky params
          controller.set('status', DEFAULT_VALUE);
        }
    },


来源:https://stackoverflow.com/questions/31732836/ember-data-resets-queryparam-to-default-value

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