sortQueryParams (obj) Object
By default, the RESTAdapter will send the query params sorted alphabetically to the server.
For example:
store.query('posts', { sort: 'price', category: 'pets' });
will generate a requests like this /posts?category=pets&sort=price
, even if the parameters were specified in a different order.
That way the generated URL will be deterministic and that simplifies caching mechanisms in the backend.
Setting sortQueryParams
to a falsey value will respect the original order.
In case you want to sort the query parameters with a different criteria, set sortQueryParams
to your custom sort function.
app/adapters/application.js
import DS from 'ember-data'; export default DS.RESTAdapter.extend({ sortQueryParams: function(params) { var sortedKeys = Object.keys(params).sort().reverse(); var len = sortedKeys.length, newParams = {}; for (var i = 0; i < len; i++) { newParams[sortedKeys[i]] = params[sortedKeys[i]]; } return newParams; } });
Parameters:
-
obj
Object
Returns:
-
Object
Please login to continue.