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

前端 未结 9 1621
天命终不由人
天命终不由人 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条回答
  •  甜味超标
    2020-12-08 01:47

    I have just written a component to make this a bit nicer:

    App.LinkLiComponent = Em.Component.extend({
      tagName: 'li',
      classNameBindings: ['active'],
      active: function() {
        return this.get('childViews').anyBy('active');
      }.property('childViews.@each.active')
    });
    
    Em.Handlebars.helper('link-li', App.LinkLiComponent);
    

    Usage:

    {{#link-li}}
      {{#link-to "someRoute"}}Click Me{{/link-to}}
    {{/link-li}}
    

提交回复
热议问题