Query-parameter associated with object attribute


#1

I’d like to define a queryParameter that’s associated with a give object attribute rather than the object itself.

So for example, I have the following:

currentObject: { firstName: 'Bender', lastName: 'Rodriguez' },

Where the query-parameter would be ?person=Bender

Is this possible?


#2

Yes. Twiddle

import Ember from 'ember';

export default Ember.Route.extend({
  queryParams: {
    'person.firstName': {
    	as: 'firstName'  
    }
  }
});

#3

Thanks! Your example works fine, but in my case the app starts up with no person selected, meaning that it’s defined as null until someone clicks the name that is.

Also I need to be able to have users set bookmarks on certain filters and this approach doesn’t work either, e.g. user click link from email and jumps to the pre-filtered list where firstname=Bender.

I’ve tried just about everything until now…


#4

How are you setting a default user in that case?


#5

My app provides a list of items with various filters which can be turned on and off and are reflected automatically in the url.

The filters currentCity or currentProvince which are mapped to strings are easy.

The hard part is that some of these filters are mapped to objects so if I map a given query-parameter to an object, the url displays the stringified object and won’t work between sessions, e.g. email links.

Basically I provide a list of names to choose from, the default when the route is entered (assuming no query-params) is null meaning that all names appear.

Only after the user clicks one of the buttons lists does that filter get enabled by setting currentXXX to the object.

Afterwards the user can disable the filter by clicking an All button which stands for the null object.