在Ember.js中使用linkTo传递与xyz_id不同的动态参数 [英] Passing a dynamic parameter different than xyz_id using linkTo in Ember.js

查看:138
本文介绍了在Ember.js中使用linkTo传递与xyz_id不同的动态参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多传递动态参数的例子,其中xyz_id是通过,xyz是model。但是,有没有办法传递与xyz_id不同的id?



基本上,给定这个小提琴: http:// jsfiddle .net / xcNSa / 11 /



有人可以告诉我如何传递视频的代码,并输入选项作为参数,而不是只是id。所以,当前链接标题为Link to myself指向:



http://fiddle.jshell.net/xcNSa/11/show/#/video/1



我想要指出:



http://fiddle.jshell.net/xcNSa/11/show/#/video/horror/event-horizo​​n



这是linkTo如何用于呈现循环中的链接:

  {{link to视频this}}链接到自己{{/ linkTo}} 


解决方案

我想出来了。必须在路由器上实现序列化方法:

  serialize:function(model,params){
return {
code:model.code,
type:model.type,
id:model.id
};
}

当然,根据路径更新:

  this.resource('video',{
path:'/ video /:type /:code'
});

http://jsfiddle.net/xcNSa/12/


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}}

解决方案

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/

这篇关于在Ember.js中使用linkTo传递与xyz_id不同的动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆