I'm using ember 2.1.0 I have 2 models - testGroup and crv.
import DS from 'ember-data';
export default DS.Model.extend({
tag: DS.attr('string'),
ctr: DS.attr('number', {defaultValue: 10}),
convs: DS.attr('number', {defaultValue: 10}),
testGroup: DS.belongsTo('testGroup')
});
And in template I show all items from testGroup.crvs with ability to change ctr/convs.
{{#each model.crvs as |crv|}}
<tr>
<td>{{crv.tag}}</td>
<td>{{input value=crv.ctr}}</td>
<td>{{input value=crv.convs}}</td>
</tr>
{{/each}}
And at the end I want tot show total:
<div>Phases: {{total}}%</div>
For this issue I created a computed property:
total: Ember.computed('model.crvs.@each.convs', function() {
var crvs = this.get('model').get('crvs');
if (crvs) {
var tmp = 0;
crvs.forEach(function(crv) {
tmp += parseFloat(crv.get('convs'));
});
return tmp;
} else {
return 0;
}
}),
It shows right value when page is rendered but when I change values in crvs collection the computed property isn't changed. I can see new value in ember console.
What's wrong with my property?
Aucun commentaire:
Enregistrer un commentaire