lundi 29 février 2016

Filtering an array in ember

Ok so I'm fairly new to programing, I know how to run a filter on a JSON Array but I cant seem to figure it out when I'm pulling the data from firebase and viewing it in an Ember app.

this is my route.js code:

    import Ember from 'ember';

    export default Ember.Route.extend({
      model: function() {
        return this.store.findAll('user');
      }
    });

This is my template.hbs code the href="#!" is the generic from materialize for the dropdown buttons:

    <div class="list-wrapper col-xs-10 col-xs-offset-1">
        <div class="col-xs-12 button-div">
           {{#md-btn-dropdown text='Filter' class="col-xs-2"            belowOrigin=true}}
               <li><a href="#!">Female</a></li>
               <li><a href="#!">Male</a></li>
               <li><a href="#!">All</a></li>
           {{/md-btn-dropdown}}
        </div>
        {{#each model as |info|}}
        <div class="col-xs-3 user-card">
           <div class="card-info">
               <ul>
                   <li>Last Name- {{info.lastName}}</li>
                   <li>First Name- {{info.firstName}}</li>
                   <li>Gender- {{info.gender}}</li>
                   <li><a href="mailto:{{info.email}}">{{info.email}} </a></li>
               </ul>
           </div>
       </div>
       {{/each}}
    </div>
    {{outlet}}

This is my controller.js code which I no is all wrong:

    import Ember from 'ember';

    export default Ember.Controller.extend({
      customFilter: function(gender) {
         return function(el) {
            var r = el.user;
            return r.gender === gender;
         };
      }
    });

and this is my model:

    import DS from 'ember-data';
    import Ember from 'ember';

    export default DS.Model.extend({
      lastName: DS.attr('string'),
      firstName: DS.attr('string'),
      gender: DS.attr('string'),
      email: DS.attr('string')
    });

I've searched high and low and I'm sure I'm just missing something basic and stupid. What I want is for the dropdown menu to be able to filter and display only female, male or all. Again I'm new to this stuff so I apologize if this is a pretty basic thing. Thank You




Aucun commentaire:

Enregistrer un commentaire