Javascript 如何将活动类分配给ampersand.js中的当前路由链接?
我有以下路线:Javascript 如何将活动类分配给ampersand.js中的当前路由链接?,javascript,backbone.js,ampersand,ampersand.js,Javascript,Backbone.js,Ampersand,Ampersand.js,我有以下路线: routes: { '': 'index', 'lifestyle': 'lifestyle', 'about': 'about' }, index: function() { }, lifestyle: function() { }, about: function() { } 如何确定哪个是活动路由,以便将“活动”类分配给相应的导航链路?最简单的方法是侦听路由器发出的路由事件,并在触发时分配您的活动类。对于您的路线定义: routes: {
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
},
index: function() {
},
lifestyle: function() {
},
about: function() {
}
如何确定哪个是活动路由,以便将“活动”类分配给相应的导航链路?最简单的方法是侦听路由器发出的
路由
事件,并在触发时分配您的活动
类。对于您的路线
定义:
routes: {
'': 'index',
'lifestyle': 'lifestyle',
'about': 'about'
}
您可以这样收听路由
事件:
router.on("route", function(page, ...arguments) {
//here 'page' can be 'index', 'lifestyle' or 'about'.
//then you can save the 'page' in a variable or assign your 'active' class right away
});
还可以查看