I'm writing an Ember.js app and have run into a small problem with using query parameters.
I have the following models: Project, Category and Designer. Project can belong to a single Category, and have multiple Designers.
I'm using a computed property on my projects controller to filter out the projects depending on which Category or Designer is selected. Everything works nice, except the following:
There's a list of Categories (links to 'projects' route with category.slug as query params) which I use to filter out projects {{#link-to 'projects' (query-params category=category.slug)}}
, e.g., #/projects?category=product
. On top of that list I placed a link which leads to a clean 'projects' route hoping that would reset/remove the 'category' query param, but that link seems to alway lead to 'projects' route with currently active query params. So, for example, if I'm looking at #/projects?category=product
the clean 'projects' route link and the 'projects (query-params...)' link behave as active link, which is a problem.
I know this can be kind of worked around by placing a default value for category param in the link-to helper for the "clean" route, but I'd like to avoid that as setting category='all'
or something similar is kind of weird for me. Is there any way to force query params to dissapear by using a link-to helper? I know it can be done by creating an action on controller and setting the query param related property to null, but it's still not an elegant solution as I'd have to fake a link.
Also, If there's a second list of Designers, which works in the same way, what would be the simplest way to have the query params be only 'category' or only 'designer', but not both? I'd like to avoid having sticky params in this use case, so nothing like #/projects?category=product&designer=john
.
Thanks!
The updated answer should be
(query-params category="null")
Note that null
is to be passed in as a string.
As andyhot suggested in his post on EmberJS Discourse, I did the following to get what I needed:
Add a controller property for the default value:
defaultCategory: null
and then in the link-to helper
(query-params category=defaultCategory)
It's kind of a workaround, but does the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With