Troubleshoot using controller compute property from view

My controller has a computed property:

App.IndexController = Ember.ArrayController.extend({

    grandTotal: function () {
        return this.getEach('total').reduce(function(accum, item) {
            return accum + item;
        }, 0);
    }.property('@each.total'),

});

but I am having trouble accessing it with my view. Here is my view:

App.SummaryView = Ember.View.extend({

    templateName: 'summary',

    companiesChanged: function() {
        Ember.run.once(this, 'logCompanies');
    }.observes('controller.@each'),

    logCompanies: function() {
        console.log(this.get('controller').get('model').get('length'));
        console.log(this.get('controller').get('grandTotal'));
    }

});

.get('length')returns correctly, so I know when it's called model loading. But it grandTotalreturns as NaN, although I know that it is correctly encoded, since it is displayed in the template. I need to access it in my view for additional reasons.

Any ideas?

+1
source share
1 answer

, @each.total, . , @each , controller.grandTotal:

App.SummaryView = Ember.View.extend({

    templateName: 'summary',

    companiesChanged: function() {
        Ember.run.once(this, 'logCompanies');
    }.observes('controller.grandTotal'),

    logCompanies: function() {
        console.log(this.get('controller').get('model').get('length'));
        console.log(this.get('controller').get('grandTotal'));
    }

});
+1

All Articles