jeudi 11 février 2016

Display a certain value based on a condition in my Emberjs Model

I am very new to Emberjs since I come from java server side world.

The actual case I'm facing to is the following. I got a Member model, like this

import DS from 'ember-data';

export default DS.Model.extend({
  firstname : DS.attr('string'),
  lastname: DS.attr('string'),
  ...      
  paid_fees : DS.hasMany('paid-fee', {async : true})
});

... and the paid-fee Model

import DS from 'ember-data';

export default DS.Model.extend({
  year : DS.attr('number'),
  amount: DS.attr('number')
});

Here is my problem, how to display a list of member and in one of the column, display for example an 'V' if one of the paid-fees has the year 2016.

Here is the template I wrote:

<table class="table table-hover">
  <tr>
    <th>Prénom</th>
    <th>Nom</th>
    <th>Email</th>
    <th>Gsm</th>
    <th>En ordre de côtisations</th>
    <th>Détails</th>
  </tr>
  <tbody>
  {{#each model as |member|}}
    <tr>
      <td>{{member.firstname}}</td>
      <td>{{member.lastname}}</td>
      <td>{{member.email}}</td>
      <td>{{member.mobilePhone}}</td>
      <td>
          /*
How-TO ??? Component ? Computed property ? Helpers ?
*/

      </td>

      <td>{{#link-to 'members.show' member}}<span class="glyphicon glyphicon-zoom-in" />{{/link-to}}</td>
    </tr>
  {{else}}
  No data available
  {{/each}}
  </tbody>
</table>

Any help ? Thanks Olivier




Aucun commentaire:

Enregistrer un commentaire