Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an array as a query parameter to the link-to helper

Tags:

ember.js

I have a queryParam in my controller that is an array like so:

export default Ember.Controller.extend({
  queryParams: ['customFilters'],
  customFilters: []  

  // Other code goes here
}

Now I want to link to this controller and provide one or many values to the customFilters queryParam as an array like so:

{{#link-to 'search' (query-params customFilters=['selection1'])}}
  Custom Selection
{{/link-to}}

Unfortunately the link-to helper doesn't seem to allow me to do that and just gives me a link to the search route with no query parameters. So I have two questions.

1) Is this something that I should be able to do?

2) Can I use the link-to helper to generate the link for me or should I try and hand roll it?

like image 378
Adam Cooper Avatar asked Sep 30 '15 16:09

Adam Cooper


1 Answers

I'm going to assume that the route with the link-to has the ability to update the filters it wants to pass. In that routes controller:

export default Ember.Controller.extend({
  arrayOfFilters: [
    'Jon Snow', 
    'Tyrion Lannister',
    'Stannis Baratheon'
  ],
  SomeFunctionThatUpdatesTheArray() {}
});

In that routes template:

{{#link-to 'search' (query-params customFilters=arrayOfFilters)}}I have custom filters!{{/link-to}}

In the search route controller:

export default Ember.Controller.extend({
  queryParams: ['customFilters'],
  customFilters: []
})
like image 71
Tyler Iguchi Avatar answered Nov 15 '22 06:11

Tyler Iguchi