javascript - How to use the Ember.Select value to filter JSON? -


i want filter json using ember.select value instead of hardcoding it. here's app.js

app = ember.application.create({});  app.indexroute = ember.route.extend({     rendertemplate : function(controller) {         this.render('myapp', {             controller : controller         });     },     model : function() {         return app.mytemplatemodel.find();     } });  app.indexcontroller = ember.arraycontroller.extend({      filteredcontent : ember.computed.oneway("content"),     last : function() {         var filtered = this.get('content').filterproperty('last_name', "solow");         this.set("filteredcontent", filtered);      } });  app.mytemplatemodel = ember.model.extend({     id : ember.attr(),     last_name : ember.attr(),     first_name : ember.attr(),     suffix : ember.attr(),     expiration : ember.attr() });  app.controller = ember.object.create({     selectedprogrammer : null,     content : [ember.object.create({         last_name : "solow",         id : 1     }), ember.object.create({         last_name : "tom",         id : 2     })] });  app.mytemplatemodel.url = "http://ankur1.local/index.php/api/example/users/"; app.mytemplatemodel.adapter = ember.restadapter.create(); var existing = app.mytemplatemodel.find(); app.mytemplatemodel.camelizekeys = true; 

in line,

 var filtered = this.get('content').filterproperty('last_name', "solow"); 

i harcoding "solow" want use ember.select value.

i tried doing this,

 var selectedprogrammer = app.controller.get("selectedprogrammer");  var filtered = this.get('content').filterproperty('lastname', app.controller.get('selectedprogrammer'));  this.set("filteredcontent", filtered); 

but nothing & moreover, here's doing on html,

<script type="text/x-handlebars" data-template-name="myapp"> {{#each item in filteredcontent }}             <tr><td>             {{id}} <p> {{item.first_name}} {{item.expiration}}</p>             </td></tr>             {{/each}}              <button {{action last}}>filter</button>              {{view ember.select             contentbinding="app.controller.content"             optionvaluepath="content.id"             optionlabelpath="content.last_name"             selectionbinding="app.controller.selectedprogrammer"}} </script> 

furthermore, here's sample of json, http://pastebin.com/7dynqi4k

where might wrong or changes might have make?

your ember.select bound app.controller.selectedprogrammer, when select changes, receive object. in controller access last_name property object using app.controller.get('selectedprogrammer.last_name').

app.indexcontroller = ember.arraycontroller.extend({     filteredcontent : ember.computed.oneway("content"),     last : function() {         var lastname = app.controller.get('selectedprogrammer.last_name');         var filtered = this.get('content').filterproperty('last_name', lastname);         this.set("filteredcontent", filtered);     } }); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -