Passing a dynamic parameter different than xyz_id using linkTo in Ember.js

本秂侑毒 提交于 2019-12-13 04:56:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!