mercredi 27 mai 2015

EmberJS Observer Not Firing

EmberJSBin here

I have a component which needs to perform a given operation when any of its values are changed, but the observer I created does not fire:

export default Ember.Component.extend({
    taxes: null,
    NOAYears: 2,
    NOAValues: Ember.computed("NOAYears", function() {
        var NOAs = [],
            lastYear = new Date().getFullYear() - 1;
        for (var year = 0; year < this.get("NOAYears"); year++) {
            NOAs.push({year: lastYear - year, value: 0});
        }
        return NOAs;
    }),
    NOAYearsChanged: function() {
        // does not fire when any of the values change
    }.observes("NOAValues.@each.value")
});

In the component template, I am binding via the {{#each}} iterator:

{{#each NOAValues as |year|}}
    <label for="{{year.year}}-value">{{year.year}}</label>
    {{input min="0" step="any" value=year.value required=true placeholder="Yearly Income"}}
{{/each}}

How can I get my observer to fire when any of the value properties in NOAValues is changed?




Aucun commentaire:

Enregistrer un commentaire