我试图让链接保持活跃状态'在多个路由上,例如/#/ users和/#/ user。
有什么想法吗?
答案 0 :(得分:5)
您可以重新打开Ember的LinkView并执行类似的操作(允许currentWhen包含空格分隔值)
Ember.LinkView.reopen({
active: function() {
// we allow link-to's currentWhen to specify multiple routes
// so we need to check each one of them
var loadedParams = Ember.get(this, 'loadedParams');
var currentWhen = this['current-when'] || this.currentWhen;
currentWhen = currentWhen || (loadedParams && loadedParams.targetRouteName);
if (currentWhen && currentWhen.indexOf(' ') >= 0) {
var currents = currentWhen.split(' ');
router = Ember.get(this, 'router');
for (var i = 0; i < currents.length; i++) {
var isActive = router.isActive.apply(router, [currents[i]]);
if (isActive)
return isActive;
}
return false;
}
return this._super();
}.property('resolvedParams', 'routerArgs')
});
答案 1 :(得分:-1)
这是完全黑客攻击,但它适用于Ember 1.0.0。要在用户路由处于活动状态时使用户链接保持活动状态:
App.UserRoute = Ember.Route.extend({
activate: function() {
setTimeout(function() {
$('[href="#/users"]').addClass("active");
}, 0);
}
});