An easy solution would be to declare categorize() as an observer :
App.IssuesController = Ember.ArrayController.extend({ issue_list: [], categorized_issues : {"open":[], "closed": []}, processIssues: function(issues) { this.set('issue_list', issues); return issues; }, categorize: function() { var self = this; // clear the arrays to avoid redundant objects in the arrays self.get("categorized_issues.open").clear(); self.get("categorized_issues.closed").clear(); this.issue_list.forEach(function(i) { // Based on the issue open or closed status if (i.status == "open") { self.get("categorized_issues.open").addObject(i); } else { self.get("categorized_issues.closed").addObject(i); } }); }.observes(" issue_list.@each "), });
This would mean that the observer would fire every time the array changes. In most cases, this will not be a performance issue. To ensure that categorize only starts once , it would be even better if you use Ember.run.once :
App.IssuesController = Ember.ArrayController.extend({ issue_list: [], categorized_issues : {"open":[], "closed": []}, processIssues: function(issues) { this.set('issue_list', issues); return issues; }, issueListObserver : function(){ Ember.run.once(this, this.categorize); }.observes(' issue_list.@each '), categorize: function() { var self = this;
source share