mercredi 24 décembre 2014

Calculation Computed Properties in Models Ember

I am trying to achieve a calculation with computed properties between a value inserted in an Input and a value selected in the option value in order to see the data stored


You can see here


This is my code in the models



App.Invoice = DS.Model.extend({
title : DS.attr('string'),
transactions : DS.hasMany('transaction', { async:true})
});

App.Transaction = DS.Model.extend({
quantity: DS.attr('string'),
fare: DS.attr('string'),
total: DS.attr('string'),
isChecked: DS.attr('boolean')
});

App.Total = Ember.Object.extend({
quantity: null,
fare: null,
total: function(){
return this.get('quantity')*this.get('fare');
}.property('quantity', 'fare')
});


And then in my template



<tr>
{{#each model.transactions}}
<td>{{name}} {{input type="checkbox" value="isChecked" checked=isChecked}} {{input type="number" value=quantity}}{{view Ember.Select prompt="Tariffa" value=fare content=controller.selectContentTariffa optionValuePath="content.value" optionLabelPath="content.label"}} {{input type="number" value=total}}</td>
{{/each}}
</tr>


Unfortunately I can not achieve it and I don’t know what I am doing wrong, however the record created for the fare and quantity are displayed correctly but not for the total, because i can not calculate it in this way


See the img


enter image description here


In comparison to that, I achieved when I made this multiplication in the controllers (see here) but obviously in this way I can not create the data record for the transaction elements (fare, quantity and total)


See the img enter image description here


So what ‘s the way to achieve this operation in order to create the record data for the quantity, fare and total?





Aucun commentaire:

Enregistrer un commentaire