Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4826

Passing dynamic query-params as an object in link-to helper

$
0
0

@siva_abc wrote:

Hello, I have a requirement as to pass query-params dynamically.

I have demostrated my idea here

model: [ 
      {
      "routeName":"laptop",
      "param": {"color":"blue"}
      },
      {
      "routeName":"mobile",
      "param": {"size":"5.5"}
      },
      {
      "routeName":"notebook",
      "param": {"display":"HD"}
      }
    ];


{{#each model as |obj|}}

     {{#if (equal obj.routeName 'laptop')}}

          {{#link-to obj.routeName (query-params color=obj.param.color)}}
                {{obj.routeName}}
          {{/link-to}}

     {{/if}}

     {{#if (equal obj.routeName 'mobile')}}

           {{#link-to obj.routeName (query-params size=obj.param.size)}}
                {{obj.routeName}}
           {{/link-to}}

     {{/if}}

     {{#if (equal obj.routeName 'notebook')}}
           {{#link-to obj.routeName (query-params display=obj.param.display)}}
                {{obj.routeName}}
           {{/link-to}}
     {{/if}}

  {{/each}}

Since, {{link-to}} doesn't support dynamic querying I had to include checks for passing query-param.

If {{link-to supports dynamic passing of query-params like below

    {{#each model as |obj|}}

        {{#link-to obj.routeName (query-params obj.param) }}
              {{obj.routeName}}
       {{/link-to}}

    {{/each}}

The code would be more pretty without any if checks !

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles