-1

I have on my page a list of clients (only names) and when I click on each one of them, I want to open a new page called 'clientdetails' in which I get the details of the client besides its name (I have an address and an age) ;

What I have so far is something like this :

{{#each model as |client|}}
    <p> {{#link-to "clientdetails"}} {{client.name}} {{/link-to}}
    </p>
  {{/each}}

How should I pass client.address and client.age to clientdetails and display them accordingly in the clientdetails page?

Thank you.

SimpleFuzz
  • 69
  • 9

1 Answers1

1

Take a look at:

https://guides.emberjs.com/v2.5.0/templates/links/

I guess you could create a route in your route.js to route to your client details:

Router.map(function() {
  this.route('clients', function(){
    this.route('clientdetails', { path: '/:client_id' });
  });
});

In your template (to link with your client details):

{{#each model as |client|}}
    <p> {{#link-to "clientdetails" client}} {{client.name}} {{/link-to}}
    </p>
 {{/each}}

Last, create a template clientdetails where you show your client details:

<p>{{model.name}}</p>
<p>{{model.address}}</p>
<p>{{model.age}}</p>

Hope it helps,

jos
  • 1,070
  • 12
  • 22
  • 2
    Keep in mind that passing the model to link-to will cause that route's model hook to be ignored, if you do want the model hook to be triggered pass the model id instead (client.id) – Patsy Issa Jul 04 '16 at 14:06
  • 1
    @Kitler still usually the right way is to pass the model itself, because a re-fetch is not necessary. – Lux Jul 04 '16 at 16:20
  • Godo point @Lux , so do you think that the right way is {{#link-to "clientdetails" client}}, right? – jos Jul 04 '16 at 17:31
  • Yes! The only reason to not directly pass the model is when you do complex things in the `model` hook. Never for the standard implementation. Its just important to understand how it works. – Lux Jul 04 '16 at 17:41