jeudi 6 avril 2017

A boolean for a condition met for a list of data in Ember Cli component

I have a hbs that displays a table for the list of data that is fed to the component

templates/components/results.hbs

 <tbody>
        
        <tr>
           <td>
                
            </td>
            <td  class="alert alert-danger" >
                
            </td>
        
</tbody>

the corresponding js file is components/results.js

export default Ember.Component.extend({

 isFailure: false,
 didInsertElement: function () {

     this.calculateFailure();
 },

 calculateFailure: function () {
    var resultDetails = this.get('resultsDetails');
    for (var resultDetail in resultDetails) {
        if (resultDetail.failures == 0) this.set('isFailure', true);
    }
}.observes('resultsDetails'),

});

I know what I am doing is wrong.

What I want is for the resultsDetails list, if the failure value is set to 0, i want the flag to be false, so in my handle bar, if the data is a failure my td class is set to alert-danger.

I am totally new to ember so most of the google and ember guides were too complex to understand. Could anyone guide me to the right direction?

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire