emberjs - how to mark active menu item using router infrastructure

前端 未结 15 1517
悲&欢浪女
悲&欢浪女 2020-11-27 13:06

I\'m trying to create navigation tabs (taken from Twitter Bootstrap):

15条回答
  •  囚心锁ツ
    2020-11-27 13:43

    If you're using Ember >= 1.11, then https://stackoverflow.com/a/14501021/65542 below is the correct answer.


    I would create a NavigationView, see http://jsfiddle.net/pangratz666/z8ssG/:

    Handlebars:

    
    

    JavaScript:

    App.NavigationView = Em.View.extend({
        templateName: 'navigation',
        selectedBinding: 'controller.selected',
        NavItemView: Ember.View.extend({
            tagName: 'li',
            classNameBindings: 'isActive:active'.w(),
            isActive: function() {
                return this.get('item') === this.get('parentView.selected');
            }.property('item', 'parentView.selected').cacheable()
        })
    });
    

    And inside your route's connectOutlets you have to set the current navigation item via router.set('navigationController.selected', 'home'); ...


    Also take a look at the ember-bootstrap repository, which wraps this and more features of Bootstrap inside Ember.js

提交回复
热议问题