问题
I've seen a lot of examples of passing dynamic parameters which end with xyz_id being passed where xyz is the "model". However, is there a way to pass an id different than xyz_id?
Basically, given this fiddle: http://jsfiddle.net/xcNSa/11/
Can someone please show me how to pass in the video's code and type options as parameters instead of just the id. So, current link titled "Link to myself" points to:
http://fiddle.jshell.net/xcNSa/11/show/#/video/1
I'd like it to point to:
http://fiddle.jshell.net/xcNSa/11/show/#/video/horror/event-horizon
This is how linkTo is being used to render the link in the loop:
{{#linkTo "video" this}} Link to myself {{/linkTo}}
回答1:
I figured it out. Had to implement the serialize method on the router:
serialize: function(model, params) {
return {
code: model.code,
type: model.type,
id: model.id
};
}
and of course, update the according path:
this.resource('video', {
path: '/video/:type/:code'
});
http://jsfiddle.net/xcNSa/12/
来源:https://stackoverflow.com/questions/15698253/passing-a-dynamic-parameter-different-than-xyz-id-using-linkto-in-ember-js