Assigning 'active' class to selected list item in EmberJS

后端 未结 12 2088
星月不相逢
星月不相逢 2020-12-08 00:34

I have a list and I\'d like to set one item as class=\"active\" automatically. Given the following bootstrap code:

12条回答
  •  感动是毒
    2020-12-08 01:21

    the active route's path is updated automatically in the ApplicationController via currentPath so I did something like that in my App... In ApplicationController added properties like so:

    isProductsActive: function(){
      if ( this.get('currentPath') === 'products' ) return 'active';
      else return '';
    }.property('currentPath')
    

    and in my ApplicationView template:

  • {{#linkTo "products"}}Products{{/linkTo}}
提交回复
热议问题