Is there a way to pass an array to currentWhen in EmberJS?

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

Any ideas?


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

This is a total hack, but it works in Ember 1.0.0. To make links to users stay active when the user route is active:

App.UserRoute = Ember.Route.extend({

    activate: function() {
        setTimeout(function() {
            $('[href="#/users"]').addClass("active");
        }, 0);
    }
});
链接地址: http://www.djcxy.com/p/73982.html

上一篇: Javascript等价于curl命令

下一篇: 有没有办法将数组传递给currentEnd在EmberJS中?