Javascript 主干+;jquery:如何从具有主干的链路检索数据';谁的路由器?

Javascript 主干+;jquery:如何从具有主干的链路检索数据';谁的路由器?,javascript,jquery,backbone.js,custom-data-attribute,jquery-1.9,Javascript,Jquery,Backbone.js,Custom Data Attribute,Jquery 1.9,如何从主干路由器的链路中检索数据?比如说, html 结果, about-us 但是我想从数据属性中获取post。可能吗 我认为你做不到这一点。当路由器知道位置变化时,对的任何引用都早已消失。路由器需要的任何东西都应该在路由本身中: routes: { '!article/edit/:url/(:type)': 'renderDynamicPage' } 这个链接看起来像: <a href='#!article/edit/about-us/post'>Edit</a

如何从主干路由器的链路中检索数据?比如说,

html

结果,

about-us

但是我想从数据属性中获取
post
。可能吗

我认为你做不到这一点。当路由器知道位置变化时,对
的任何引用都早已消失。路由器需要的任何东西都应该在路由本身中:

routes: {
    '!article/edit/:url/(:type)': 'renderDynamicPage'
}
这个链接看起来像:

<a href='#!article/edit/about-us/post'>Edit</a>
修补
href
s。或者,您可以将
单击
处理程序添加到您关心的所有
中,并在更新
窗口.位置之前手动将
数据类型
合并到URL片段中

routes: {
    '!article/edit/:url/(:type)': 'renderDynamicPage'
}
<a href='#!article/edit/about-us/post'>Edit</a>
$('a[data-type]').each(function() {
    var $this = $(this);
    $this.attr('href', $this.attr('href') + $this.data('type'));
});