mardi 22 décembre 2015

Ember search in current model

This code for search in hasMany childrens work like a charm. But i want search in current model (e.g. filtered by store name: 'storeOne'), that is reason because i want search in current model, not query to this.store and not query to api...

        var _self = this;
        this.store.findAll('store').then(function(stores){

            // search
            var promises = stores.map(function(store){

                return Ember.RSVP.hash({
                    store: store,
                    customers: store.get('customers').then(function(customers){
                        return customers.filter(function(customer){
                            var regExp = new RegExp(search, 'i');

                            var retVal = false;

                            if (customer.get('name') !== undefined ) retVal = retVal || customer.get('name').match(regExp);
                            if (customer.get('surname') !== undefined ) retVal = retVal || customer.get('surname').match(regExp);
                            if (customer.get('age') !== undefined ) retVal = retVal || customer.get('age').match(regExp);

                            return retVal;
                        });
                    })
                });

            });

            Ember.RSVP.all(promises).then(function(filteredData){
                _self.set('content', filteredData);
            });
        });

  • Question: How can i filter by search customers in current model without use findAll or query to API ?



Aucun commentaire:

Enregistrer un commentaire