Ember js link-to dynamic query param

i will explain it with example

{{#link-to item.targetUrl (query-params randomParam=value.id) class="link-wrap"}}abc{{/link-to}}

if targeturl is abc.xyz this will give me href="#/abc/xyz?randomParam=2"

How to have a dynamic param??? randomParam is not going to be same, it might be randomParm1 or randamParm2 so i want something like below:

{{#each selectedTab.content as |item|}}

      {{#each item.values as |value|}}
      <li {{action 'itemSelect' item.targetUrl item.param }}>{{#link-to item.targetUrl (query-params item.param=value.id) class="link-wrap"}}{{value.desc}}{{/link-to}}</li>
      {{/each}}

  {{/each}}

here item.param is dyanamic. I am not really looking for work arounds since i figured out a solution using this.transitionTo from an action in template. I am looking for how to solve this in {{link-to}} helper.

Answers


You can pass in arguments as a hash instead of positional parameters (which is what you're doing right now).

So you'd do something like:

// template.hbs
{{#link-to params=myParams}}
    Some text
{{/link-to}}


// component.js
{
    myParams: ['your.route.string']
}

Now if you have more sophisticated routes with dynamic segments or query params:

Dynamic Segments

If you have a dynamic segment, your router might look something like:

// router.js
this.route('users', function(){
    this.route('user', {path: '/:username'})
});

then you'd do something like:

// template.hbs
{{#link-to params=myParams}}
    Some text
{{/link-to}}


// component.js
{
    myParams: ['users.user', 'SOME_USERNAME']
}
Query {arams

If you have query parameters and your controller looks like:

// controller.js
{
    queryParams: ['foo', 'bar']
}

then you'd do something like:

// template.hbs
{{#link-to params=myParams}}
    Some text
{{/link-to}}


// component.js
{
    myParams: ['some.route.string, {
        isQueryParams: true,
        values: {
            foo: 'some_value',
            bar: 'another_value',
        }   
    }]
}

Note that the query param object has to be last in the array. So if you have a dynamic segment as well, it would look like

myParams: ['some.route.string', 'someDynamicID', {queryObject}]

Need Your Help

execfile with automatic relative path

python python-2.7 ironpython execfile

I need to be able to call python scripts via execfile() from outside the working directory without specifying the relative file path each time through the interpreter.

Replacing every instance of a character in Python string

python

I have a game where the user guesses letters. They are shown a blank version of the mystery work (_____ for example, the _'s are equal to number of characters in the word). The program knows the wo...