Ember.js 在紧接着调用TransitionRoute()时,Ember不更新查询参数
在我的应用程序中,我有一个总体控制器,用于管理应用程序一部分的状态,称为Ember.js 在紧接着调用TransitionRoute()时,Ember不更新查询参数,ember.js,Ember.js,在我的应用程序中,我有一个总体控制器,用于管理应用程序一部分的状态,称为SimpleSearch 在SimpleSearch中,我有多个SimpleSearchOptions,它们向用户显示选项列表 用户可以选择一个选项,该选项是从视图中调用的一个操作,会弹出到SimpleSearchOptionController: App.SimpleSearchOptionController = Ember.ObjectController.extend({ //.... select: fun
SimpleSearch
在SimpleSearch
中,我有多个SimpleSearchOption
s,它们向用户显示选项列表
用户可以选择一个选项,该选项是从视图中调用的一个操作,会弹出到SimpleSearchOptionController
:
App.SimpleSearchOptionController = Ember.ObjectController.extend({
//....
select: function (option) {
option.queryName = this.get('queryName');
this.get('simpleSearch').setSelection(option);
this.set('selectedOption', option);
this.set('hasSelectedOption', true);
this.send('transitionToNextOption');
},
//....
App.SimpleSearchController = Ember.ObjectController.extend({
//....
setSelection: function (option) {
this.set(option.queryName, option.value);
this.get('selectedOptions').set(option.queryName, option.value);
this.get('model').notifyPropertyChange('selectedOptions');
this.checkIfAllOptionsSelected();
},
//....
此操作调用This.get('simpleSearch').setSelection(选项)
,它将选择注册到SimpleSearchController
:
App.SimpleSearchOptionController = Ember.ObjectController.extend({
//....
select: function (option) {
option.queryName = this.get('queryName');
this.get('simpleSearch').setSelection(option);
this.set('selectedOption', option);
this.set('hasSelectedOption', true);
this.send('transitionToNextOption');
},
//....
App.SimpleSearchController = Ember.ObjectController.extend({
//....
setSelection: function (option) {
this.set(option.queryName, option.value);
this.get('selectedOptions').set(option.queryName, option.value);
this.get('model').notifyPropertyChange('selectedOptions');
this.checkIfAllOptionsSelected();
},
//....
其中重要的一行是:this.set(option.queryName,option.value)代码>
注册选择后,它会移动到下一个选项,如果没有,它会跳转到搜索结果。从this.send('transitiononnextoption')调用的代码>
设置属性(this.set(option.queryName,option.value);
)实际上会产生一个副作用,即在URL中更新查询参数,这就是我的意图。如果我包括该行,并在设置该变量后转换到其他路由,则查询参数不会更新
我正在浏览Ember的代码,但我不太明白它是如何处理的。它一直延续到\u doTransition()
,我注意到,到路由“simpleSearchResults”的转换总是在通过queryParams之前发生
如何让Ember在查询参数转换为“simpleSearchResults”之前更新它
感谢您提供的所有帮助。我通过将转换包装到函数中解决了我的问题:
transitionToNextOption: function () {
var nextOptionId = parseInt(this.get("id")) + 1;
var numOfOptions = this.get('simpleSearch.numOfOptions');
if (nextOptionId < numOfOptions) {
this.transitionToRoute('simpleSearchOption', nextOptionId);
}
else {
var self = this;
Ember.run.next(function() { self.transitionToRoute('simpleSearchResults'); });
}
},
transitionNext主题:函数(){
var nextOptionId=parseInt(this.get(“id”))+1;
var numOfOptions=this.get('simpleSearch.numOfOptions');
if(nextOptionId
我假设,但尚未验证,Ember正在排队将操作转换为“simpleSearchResults”,并以类似方式处理查询参数。可能到不同路由的转换以某种方式中断或覆盖了正在写入URL的查询参数