mardi 1 mars 2016

Emberjs dynamically add query param

Is it possible to dynamically add query parameters? I have a generic route and controller pair that I would like to extend for different routes(resources) to add specific query params.

I tried adding init() to both the route and the controller like:

App.ApplicationRoute = Ember.Route.extend({
    queryParams: {
        sortBy: { refreshModel: true }
    },
    init: function() {
        var query_params = this.get('queryParams');
        query_params['q'] = { refreshModel: true };
        this.set('queryParams', query_params);
        this._super();
    },
    ...

Ember.ArrayController.extend({
    queryParams: ['sortBy'],
    sortBy: 'firstName',
    init: function() {
        var query_params = this.get('queryParams');
        query_params.push('q');
        this.set('queryParams', query_params);
        this.set('q', 'qval');
        this._super();
    }
    ...

but the dynamically added query param does not show up in the route model function params parameter in the next invocation.

Is there a way to do something like this?

jsbin here: http://ift.tt/1Lv0vwM




Aucun commentaire:

Enregistrer un commentaire