Ember fire filter data in controller

259 views Asked by At

I'm new to ember, what I've created is a task manager app in Ember. I've got a model for tasks which is the following:

import DS from 'ember-data';

export default DS.Model.extend({
    title: DS.attr('string'),
    location: DS.attr('string'),
    date: DS.attr('date'),
    archive: DS.attr('boolean'),
});

I've also got it to show all the tasks for this model in a tasklist page. However I'm currently having issues of filtering only the tasks where archive is not equal to true.

In my tasklist route I've got this to pull through my task

model: function () {    
        return this.store.findAll('task');   
    }

However i need this to filter all tasks where archive is equal to false. I do I add this here or into my controller.

Updated

I've added this to my controller:

filteredModel: Ember.computed('model', function(){
        let model = this.get('model');

        return model.filter(function(item){
            return item.data.archive == false;
        });

    }),

This kind of work, so its displaying a filtered list however when I add a new item to the list it doesnt update the list, with the new item.

1

There are 1 answers

8
Ember Freak On BEST ANSWER

Introduce the computed property in controller which will return the filtered taskList,

notArchivedTask: Ember.computed.filterBy('model','archive',false)