ember.js - Ember not updating query parameters when calling transitionToRoute() right after -
in application, have overall controller manages state portion of application, called simplesearch.
within simplesearch, have multiple simplesearchoptions, display list of choices user.
a user can select option, , selection action called view, bubbles 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'); }, //.... this action calls this.get('simplesearch').setselection(option);, registers selection simplesearchcontroller:
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(); }, //.... the important line in there is: this.set(option.queryname, option.value);.
after registers selection, moves next option, , if there isn't one, skips results of search. called this.send('transitiontonextoption');
app.simplesearchoptioncontroller = ember.objectcontroller.extend({ //.... transitiontonextoption: function () { var nextoptionid = parseint(this.get("id")) + 1; var numofoptions = this.get('simplesearch.numofoptions'); if (nextoptionid < numofoptions) { this.transitiontoroute('simplesearchoption', nextoptionid); } else { this.transitiontoroute('simplesearchresults'); } }, //.... in setselection() above, line this.set(option.queryname, option.value); setting query parameter's value. works correctly, , url gets updated accordingly options, when i'm not transitioning different route.
if comment out lines:
else { this.transitiontoroute('simplesearchresults'); } setting property (this.set(option.queryname, option.value);) has side effect of ember updating query parameter in url, intent. if include line, , transition different route after setting variable, query parameter not updated.
i stepping through ember's code, can't quite follow how handles this. continues _dotransition(), , i've noticed transition route 'simplesearchresults' happens before queryparams passed through.
how ember update query parameter before transitions 'simplesearchresults'?
thank , help.
i solved issue wrapping transition in ember.run.next() function:
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'); }); } }, i'm assuming, have not verified, ember queuing action transition 'simplesearchresults', , handles query parameters similarly. perhaps transition different route somehow interrupting or overwriting query parameter being written url.
Comments
Post a Comment