Ember.js: Calculate the sum of a property of all child models

前端 未结 3 1423
醉梦人生
醉梦人生 2021-02-07 10:57

My application has the following models:

App.Store = DS.Store.extend({
    revision: 11,
    adapter: \'DS.FixtureAdapter\'
});

App.List = DS.Model.extend({
            


        
3条回答
  •  不要未来只要你来
    2021-02-07 11:22

    When using coffeescript, I like to use the one-line syntax, first getting the property values array with .mapBy('propertyName') and then using a simple coffeescript reduce:

    @get('users').mapBy('tweetsUnread').reduce (a, b) -> a + b
    

提交回复
热议问题