Ember-data将queryParam重置为默认值 [英] Ember-data resets queryParam to default value

查看:194
本文介绍了Ember-data将queryParam重置为默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  queryParams:{
状态:{
refreshModel:true
}
}

在我的控制器中,默认情况下,此参数设置为打开:

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

每当我将此参数设置为其他内容时,例如全部,Ember数据将其重置为'打开',并​​且对我的模型钩子进行两个调用而不是一个调用,并且我的模型钩子上的断点(我不知道它在哪里复位)观察到这个行为,一个是param:打开的,另一个是param:all。我甚至把一个观察者,它有效地做到这一点。



请注意,我已经搜索了我的代码,并且我没有地方将这个参数设置为原始值。



任何提示?

解决方案

你的控制器成为你路由中的预期参数

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

Ember具有粘性参数,如文档所述。


默认情况下,Ember中的查询参数值为sticky,因为如果
更改为查询参数,然后离开并重新输入路由,
将会保留该查询param的新值(而不是将
重置为默认值)。这是一个特别方便的默认值,用于在路由之间来回导航时保留
sort / filter参数。


您可以检查更多在这里... ember查询参数



您可以尝试在路由中重新设置

  resetController:function(controller,isExiting ,转换){
if(isExiting){
//重置控制器以避免粘贴参数
controller.set('status',DEFAULT_VALUE);
}
},


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?

解决方案

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);
        }
    },

这篇关于Ember-data将queryParam重置为默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆