lundi 1 août 2016

Map controller property to different query parameter key

In the EmberJS documentation there are two ways to map a controller property to a different query-param key.

Controller

In the controller by creating an object instead of a string in the queryParams array:

export default Ember.Controller.extend({
  queryParams: ['page', 'filter', {
    category: 'articles_category'
  }],
  category: null,
  page: 1,
  filter: 'recent'
});

Route

In the route by mapping with an alias:

export default Ember.Route.extend({
  queryParams: {
    category: {
      // By default, the query param URL key is the same name as
      // the controller property name. Use `as` to specify a
      // different URL key.
      as: 'articles_category'
    }
  }
}

Which one is the best way to configure the mapping? And why are there two ways?




Aucun commentaire:

Enregistrer un commentaire