本文介绍了有没有办法通过一个数组到当前在EmberJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想尝试让多个路线上的链接保持活跃,如/#/ users和/#/ user。 / p>

解决方案

您可以重新打开Ember的LinkView并执行此操作(允许当前包含空格分隔值)

  Ember.LinkView.reopen({
active:function(){
//我们允许链接到当前指定多个路由
//所以我们需要检查每一个
var loadedParams = Ember.get(this,'loadedParams');
var currentWhen = this ['current-when'] || this.currentWhen;
currentWhen = currentWhen ||(loadedParams&& loadedParams.targetRouteName);

if(currentWhen&&& currentWhen.indexOf('')> = 0 ){
varcurrent = currentWhen.split('');
router = Ember.get(this,'router');

for(var i = 0; i< currents.length; i ++){
var isActive = router.isActive.apply(router,[flows [i]]);
if(isActive)
return isActive;
}

return false;
}

return this._super();
} .property('resolvedParams','routerArgs')
});


I'm trying to make a link stay 'active' on multiple routes, such as /#/users and /#/user.

Any ideas?

解决方案

You can reopen Ember's LinkView and do something like this (allows currentWhen to contain space delimited values)

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')
});

这篇关于有没有办法通过一个数组到当前在EmberJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:40