How do I bind to the active class of a link using the new Ember router?

前端 未结 9 1619
天命终不由人
天命终不由人 2020-12-08 01:17

I\'m using Twitter Bootstrap for navigation in my Ember.js app. Bootstrap uses an active class on the li tag that wraps navigation links, rather th

9条回答
  •  猫巷女王i
    2020-12-08 01:41

    For the same problem here I came with jQuery based solution not sure about performance penalties but it is working out of the box. I reopen Ember.LinkView and extended it.

    Ember.LinkView.reopen({
        didInsertElement: function(){
            var el = this.$();
    
            if(el.hasClass('active')){
                el.parent().addClass('active');
            }
    
            el.click(function(e){
                el.parent().addClass('active').siblings().removeClass('active');
            });
        }
    });
    

提交回复
热议问题