lundi 4 juin 2018

Ember transitionTo queryParams not updating the model or URL

I am trying to use queryParams to update and refresh the model. I've set it up the action to use route-action because the change event that's firing the action is within a component. I've installed ember-route-action-helper and the change event is working correctly, but the transitionTo is not being updated.

In filter-list.hbs

<input type="checkbox"
  class="filter-checkbox inp-"
  value=""
  onchange=>

In routes/results.js

export default Ember.Route.extend({

queryParams: {
  status: {
    refreshModel:true
  },
  owner: {
    refreshModel:true
  }
},

params: null,

model(params) {
  this.set('params', params);
  return Ember.RSVP.hash({
    result: this.store.query('result', params),
    filter: this.store.findAll('filter'),
    params: params,
  });
},

setupController(controller, model) {
  this._super(...arguments);
  controller.set('result', model.result);
  controller.set('filter', model.filter);
  controller.set('params', model.params);
},

actions: {
  newParams(data){
    console.log("Received", data);
  },
  updateQuery: function() {
    //I make a URL string here from multiple checkboxes
    //and parse the URL string as a JSON object which is
    //modeled the same as a normal queryParameter
    let newParams = JSON.parse('{"' + decodeURI(urlString).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
    console.log(newParams);
    this.transitionTo({queryParams: {newParams}});
  }
}

So, I first pull the params from the URL and send them down to fetch the results and also populate a filter list (list of checkboxes with filter names). Every time I click on a filter, if it sees the checkbox has changed, it fires the updateQuery action under the route using route-action.

The action runs (and I get the correct newParams output in the console. The line that's not working is this.transitionT(). The transition is not doing anything whatsoever. It's not updating the model, it's not changing the URL, nothing.

What am I missing?




Aucun commentaire:

Enregistrer un commentaire