serialize (model, params) Objectpublic
A hook you can implement to convert the route's model into parameters for the URL.
App.Router.map(function() {
this.route('post', { path: '/posts/:post_id' });
});
App.PostRoute = Ember.Route.extend({
model: function(params) {
// the server returns `{ id: 12 }`
return Ember.$.getJSON('/posts/' + params.post_id);
},
serialize: function(model) {
// this will make the URL `/posts/12`
return { post_id: model.id };
}
});
The default serialize method will insert the model's id into the route's dynamic segment (in this case, :post_id) if the segment contains 'id'. If the route has multiple dynamic segments or does not contain 'id', serialize will return Ember.getProperties(model, params)
This method is called when transitionTo is called with a context in order to populate the URL.
Parameters:
-
model
Object - the routes model
-
params
Array - an Array of parameter names for the current route (in the example, `['post_id']`.
Returns:
-
Object - the serialized parameters
Please login to continue.