jeudi 19 avril 2018

Ember: modify model in a route

I am working on an Ember app and I am having issues. I have to filter out results at a certain point of app, say, in a controller or in a view, like this:

At view.hbs I am eliminating passed tests at ...:

<br>
    
        
    


I can do it at a controller that initially loads and can filter out in an input field:

import Controller from '@ember/controller';
export default Controller.extend({
    actions: {
        filterByTest: function (param) {
            if (param !== '') {
                return this.get('store').query('test', { name: param }).then((filteredTests) => {
                    return { query: param, tests: filteredTests.filterBy('passed', true) };
                });
            } else {
                return this.get('store').findAll('test').then((tests) => {
                    return { query: param, tests: tests.filterBy('passed', true) };
                });
            }
        }
    }
});

Now I need to filter out at a route level. model() in a route is can't be edited, if it can, then it has to be a path, which I don't want. How can I achieve that? How can I make model editable? At the moment I can get to the route model, but it can't be edited. Here's the way I talk to the model from view.hbs file and it works.

<br>
    


Please see below the model that returns file to above view.hbs template. Again, it is working:

import Route from '@ember/routing/route';

export default Route.extend({
    model() {
        return this.get('store').findAll('test').then(tests => {
            return tests('passed', true);
        })
    }
});

How can I pass argument to the model and edit it, so that my UI gets changed as well?

This is my model I need to modify. At the moment the return works, but not modifiable.




Aucun commentaire:

Enregistrer un commentaire