javascript - How can I return only filtered model in Emberjs? -
i have ember.select filters model based on roles. @ moment, when app initiates full contents of model shown want show model when filters applied. clueless on how gonna that.
here's controller in question,
app.twodcontroller = ember.arraycontroller.extend({ //filteredcontent : null, sortproperties: ['firstname'], sortascending: true, selectedexperience : null, experience : [{ exp : "1" }, { exp : "2" }, { exp : "3" }, { exp : "4" }, { exp : "5" }], selecteddesignation : null, filterdesignation : function() { var designation = this.get('selecteddesignation.designation'); var filtered = this.get('content').filterproperty('designation', designation); this.set("filteredcontent", filtered); }.observes('selecteddesignation'), designations : [{ designation : "design", id : 1 }, { designation : "writer", id : 2 }, { designation : "script", id : 3 }, { designation : "storyboard", id : 4 }, { designation : "workbook", id : 5 }], actions : { filterexperience : function() { var experience = this.get('selectedexperience.exp'); var filtered = this.get('content').filterproperty('experience', experience); this.set("filteredcontent", filtered); }, refresh : function() { var refresh = this.get('content'); this.set("filteredcontent", refresh); } }, filteredcontent : function() { var searchtext = this.get('searchtext'), regex = new regexp(searchtext, 'i'); return this.get('model').filter(function(item) { var fullname = item.firstname + item.lastname; return regex.test(fullname); }); }.property('searchtext', 'model') });
moreover, 1 more issue having not able sort ascending order. changes need in code achieve desired result?
here's full jsbin if anyone's interested.
in app.twodcontroller
include:
init: function() { this.set('filteredcontent', []); },
and in filterdesignation
change this.get('content')
this.get('arrangedcontent')
per the ember.sortablemixin documentation.
filterdesignation : function() { var designation = this.get('selecteddesignation.designation'); var filtered = this.get('arrangedcontent').filterproperty('designation', designation); this.set("filteredcontent", filtered); }.observes('selecteddesignation'),
Comments
Post a Comment