Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Ember Query Param API examples
@oxodesign

This comment has been minimized.

Show comment Hide comment
@oxodesign

oxodesign Jan 5, 2014

How can I send the query-params to the server?

How can I send the query-params to the server?

@joelkallman

This comment has been minimized.

Show comment Hide comment
@joelkallman

joelkallman Jan 6, 2014

If you are using Ember Data, you can do this with the filter() method. The filter method returns an array that will auto-update as other entries are found. http://emberjs.com/guides/models/frequently-asked-questions/

If you are using Ember Data, you can do this with the filter() method. The filter method returns an array that will auto-update as other entries are found. http://emberjs.com/guides/models/frequently-asked-questions/

@machty

This comment has been minimized.

Show comment Hide comment
@machty

machty Jan 7, 2014

Owner

machty commented Jan 7, 2014

@kamal

This comment has been minimized.

Show comment Hide comment
@kamal

kamal Jan 7, 2014

@machty is there a way to pass query-params a context, instead of the current controller?

kamal commented Jan 7, 2014

@machty is there a way to pass query-params a context, instead of the current controller?

@Kerrick

This comment has been minimized.

Show comment Hide comment
@Kerrick

Kerrick Jan 8, 2014

This looks pretty great at first glance! Has any consideration been made for something like Matrix URLs to remove the requirement for sticking everything after the query string, even when it may semantically belong elsewhere?

This would allow a URL to look like:

#/magazines;publisher=machty;audience=moviegoers/issues

Instead of:

#/magazines/issues?magazines[publisher]=machty&magazines[audience]=moviegoers

Kerrick commented Jan 8, 2014

This looks pretty great at first glance! Has any consideration been made for something like Matrix URLs to remove the requirement for sticking everything after the query string, even when it may semantically belong elsewhere?

This would allow a URL to look like:

#/magazines;publisher=machty;audience=moviegoers/issues

Instead of:

#/magazines/issues?magazines[publisher]=machty&magazines[audience]=moviegoers
@machty

This comment has been minimized.

Show comment Hide comment
@machty

machty Jan 9, 2014

@kamal i'm not sure what you mean, seems like the answer's definitely yes though {{link-to (query-params anythingYouWant)}}

Owner

machty commented Jan 9, 2014

@kamal i'm not sure what you mean, seems like the answer's definitely yes though {{link-to (query-params anythingYouWant)}}

@evalcraciun

This comment has been minimized.

Show comment Hide comment
@evalcraciun

evalcraciun Jun 17, 2014

@machty this works for a route like this ?
/letters?occup=Primary&state=NY&propertyRef=55
Primary, NY and 55 are some values from a Fixture Model
The route above is suppose to change when you click on a link

Thanks!

@machty this works for a route like this ?
/letters?occup=Primary&state=NY&propertyRef=55
Primary, NY and 55 are some values from a Fixture Model
The route above is suppose to change when you click on a link

Thanks!

@HeyBillFinn

This comment has been minimized.

Show comment Hide comment
@HeyBillFinn

HeyBillFinn Aug 29, 2014

Are there any examples of using query params with an Ember.Select view?

Are there any examples of using query params with an Ember.Select view?

@dlcwalkoff

This comment has been minimized.

Show comment Hide comment
@dlcwalkoff

dlcwalkoff Oct 9, 2014

Is it possible to pass an entire object to the queryParams?

For example:

queryParams: ['filters'],
filters: {
  name: 'Ivan',
  age: 666
}

In the address bar, in theory, it should look like this: ```?filters[name]=ivan&filters[age]=666
But how to do it?

Tried your Gist - https://gist.github.com/machty/7923797 - but in Ember 1.7.0 this don't work :)

Is it possible to pass an entire object to the queryParams?

For example:

queryParams: ['filters'],
filters: {
  name: 'Ivan',
  age: 666
}

In the address bar, in theory, it should look like this: ```?filters[name]=ivan&filters[age]=666
But how to do it?

Tried your Gist - https://gist.github.com/machty/7923797 - but in Ember 1.7.0 this don't work :)

@kriskhaira

This comment has been minimized.

Show comment Hide comment
@kriskhaira

kriskhaira Jul 2, 2015

@dlcwalkoff: Did you ever figure out an easy way to pass an object in the URL like that?

@dlcwalkoff: Did you ever figure out an easy way to pass an object in the URL like that?

@sarus

This comment has been minimized.

Show comment Hide comment
@sarus

sarus Nov 7, 2015

+1 on how to use objects in the query params (e.g., /book/5?filter[chapter]=Chapter1). This style is used heavily in json api and should be supported by Ember. Any ideas on how to go about it? It's also recommended for paging /books?page[number]=1&page[size]=100

sarus commented Nov 7, 2015

+1 on how to use objects in the query params (e.g., /book/5?filter[chapter]=Chapter1). This style is used heavily in json api and should be supported by Ember. Any ideas on how to go about it? It's also recommended for paging /books?page[number]=1&page[size]=100

@sarus

This comment has been minimized.

Show comment Hide comment
@sarus

sarus Nov 7, 2015

Just came up with a way to use object based query params which seems to work:

In the controller you need to map the controller property to your query param key:

queryParams: ['sort',{
    entityNameFilterValue: 'filter[entity.entity-name]'
  }],

Then in the routers model function you need to construct the params however you want based on the controller value:

model: function(params){
    if(params.entityNameFilterValue){
      params.filter = {};
      params.filter['entity.entity-name'] = params.entityNameFilterValue;
      delete params.entityNameFilterValue;
    }
    // do your store lookup now with params
}

sarus commented Nov 7, 2015

Just came up with a way to use object based query params which seems to work:

In the controller you need to map the controller property to your query param key:

queryParams: ['sort',{
    entityNameFilterValue: 'filter[entity.entity-name]'
  }],

Then in the routers model function you need to construct the params however you want based on the controller value:

model: function(params){
    if(params.entityNameFilterValue){
      params.filter = {};
      params.filter['entity.entity-name'] = params.entityNameFilterValue;
      delete params.entityNameFilterValue;
    }
    // do your store lookup now with params
}
@tchan

This comment has been minimized.

Show comment Hide comment
@tchan

tchan Jul 31, 2017

Thanks for this!

tchan commented Jul 31, 2017

Thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment