Saved record's length

how would i get the total length of saved records?

‘controller.content.length’ includes records with ‘isNew’ state

savedCount: function() {
    return this.get('model').filter(function(record) {
        return !record.get('isNew');
    }).length;
}.property('controller.model.@each.isNew')

Alternatively (assuming you’re working in an array controller):

The solution above works…though, you’re going to be filtering the entire array every time a new element is added, removed, or if the isNew property changes on any of the items. This solution uses ArrayComputed to ensure changes are only processed when needed.

export default Ember.ArrayController.extend({
  savedRecords: Ember.computed.filterBy('@this', 'isNew'),
  savedCount: Ember.computed.alias('savedRecords.length')
});
1 Like