Hello there. I’m using Ember 2.4.1, and i’m getting trouble trying to run queryParams with dynamic values.
Long story short, the application needs to filter a table by it’s columns, but the columns are user generated through the application… So, i need first to get the column results to build a queryParams array.
Problem is that queryParams is executed before the model (i guess), and trying to update it in the afterModel hook, or with an Ember.computed results in a non-functional queryParams. =/
I thought about something with initializer… but the columns generated is based on the selected product… so i don’t know if it will be effective.
Does some one here have ever faced some issue like this? Is there a good way to deal with this problem?
You could just use an object as query param. E.g.
queryParam: ['filters'],
filters: { col1: X, cols2: Y }
While the URL generated by this will not be super pretty, it should still work - you can just JSON.stringify()
the object as a whole.
This is the first thing i’ve tried… But it needs to directly set value to filters.col1 in order to the queryParams and refreshModel to work propertly… the queryParams doesn’t observes the child properties… I’ve even gave a try with the .notifyPropertyChange method to force notify queryParams that the filter property did changed, but no luck in that. =(
Currently i’m running a loop in the filters property in the route model hook and assigning it to the params object…
With that, all filters properties began to be sent, but model doesn’t refresh, and the URL params are not updated… To auto-refresh the model, i’m currently updating a “filter.update” static property with a random number alongside with the other filters, just to get the queryParams and refreshModel to update the model. (refresh() and update() methods lead to some inconvenient side-effects for me).
I let this issue in stand-by to solve other bugs, but when i get this one back, i will run a loop in the filters property and build a HASH, and then update a “filter.hash” property, propertly observed by the queryParams… But my component will need to manually decrypt the hash, build selected filters in the component and set all the filters from de hash…
Yeah… it’s very far from a good solution, but at least i’m pretty confident this approach will work fine.
Any update in the issue i let you guys know.
You can implement your own queryParam serialization scheme through Ember.Route#serializeQueryParam
and Ember.Route#deserializeQueryParam
hooks. I think you can use these to encode more information.
Oh, didn’t know about these hooks! I will definitely take a look into these ones!
Thanks @lightblade!