A
A
Argenon2015-08-13 19:10:52
Ember.js
Argenon, 2015-08-13 19:10:52

Ember. How to filter data?

I am using CouchDB as a database.

//route
import Ember from 'ember';

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

//model
import DS from "ember-data";

export default DS.Model.extend({
  assigned: DS.attr('string'),
  client: DS.attr('string'),
  contact: DS.attr('string'),
  date_finish: DS.attr('string'),
  date_start: DS.attr('string'),
  priority: DS.attr('string'),
  state: DS.attr('string'),
  text: DS.attr('string'),
  title: DS.attr('string'),
});

I get the necessary data from the database. How to filter the data, for example by the "state" field?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Romanov, 2015-08-13
@Argenon

Depends on how you use the data.

export default Ember.Route.extend({
  model: function () {
    return this.store.findAll('task').then(function(tasks){
        return tasks.filterBy('state', 'done');
    });
  }
});

or
export default Ember.Component.extend({
  filtredData: function() {
    return this.get('data').filterBy(this.get('filterKey'), this.get('filterValue'));
  }.property('data', 'filterKey', 'filterValue')
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question