ember.js – 有没有办法在EmberJS中将数组传递给currentWhen?

前端之家收集整理的这篇文章主要介绍了ember.js – 有没有办法在EmberJS中将数组传递给currentWhen?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使链接在多个路由上保持“活动”,例如/#/ users和/#/ user.

有任何想法吗?

解决方法

您可以重新打开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')
});

猜你在找的JavaScript相关文章