ember.js - Sort computed property on an ArrayController -


i have following jsbin: http://jsbin.com/okoxim/4/edit

filteredcontent computed property filtering controller's content. want know how sort computed property , ways can improve code have.

app.studentscontroller = ember.arraycontroller.extend({   sortproperties: ['name'],   namefilter: null,   filteredcontent: function(){     if(!this.get('namefilter')) return this.get('content');      var nameregex = new regexp(this.get('namefilter'), 'i');     return this.filter(function(item) {       return item.get('name').search(nameregex) !== -1;     });   }.property('namefilter', '@each.name') }); 

easiest way wrap result in arrayproxy sorts on same sortproperties values. like,

filteredcontent: function(){   var result;    if (!this.get('namefilter')) {     result = this.get('content');         } else {     var nameregex = new regexp(this.get('namefilter'), 'i');     result = this.filter(function(item) {       return item.get('name').search(nameregex) !== -1;     });   }    var sortedresult = em.arrayproxy.createwithmixins(     ember.sortablemixin,      { content:result, sortproperties: this.sortproperties }   );    return sortedresult; }.property('namefilter', '@each.name') 

here's updated jsbin.

another way make filteredcontent explicit arrayproxy , filter/sort on that.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -