vendredi 25 décembre 2015

EmberJS 2.x , resorting or filtering records from store via actions

Consider the following code in your js file:

App.ApplicationRoute = Ember.Route.extend({
    model: function(){
        return this.store.findAll('team');
    }
});

In your html file, you might have something like this:

{{#each model as |team|}}
<ul>
    <li>{{team.name}}</li>
    <li>{{team.email}}</li>
    <li>{{team.state}}</li>
    <li>{{team.position}}</li>
</ul><br>___<br>
{{/each}}

And the result would be something like

  • Bob Smith
  • bob.smith@bobsmithinc.com
  • NY
  • Leader


  • Jane Smith

  • jane.smith@janesmithinc.com
  • NY
  • Finance


  • John Doe

  • john.doe@janesmithinc.com
  • CA
  • Support

The question is, how would you go about sorting or filter this data after it's displayed? For example, if I want to sort by alphabetical order by name, or email, or lets say I only want to display someone in NY, and not CA.... or maybe type as I search, so if I type 'inc.com'... anyone that has that in their record will show?

My guess is this occurs in the controller via an Action? I just don't understand how to grab the store data (WITHOUT a network request) and resort or filter the data that's already there. I know you can use 'peek', but am unsure how to display the data.




Aucun commentaire:

Enregistrer un commentaire