2
votes

i have 3 tabs navigation and the content of each tab is different obviously. i'm thinking about using StateManager in Emberjs to manager my tab views.

http://docs.emberjs.com/#doc=Ember.StateManager&src=false

is that a good idea? or is there a better router out there? i've looked at

  1. sproutcore-routing
  2. ember-routemanager

are those better than the statemanager? what's the reason not to use statemanager?

1

1 Answers

5
votes

You can use something along this lines, see http://jsfiddle.net/pangratz666/e3wM7/:

Handlebars:

<script type="text/x-handlebars" >
    <ul>
        <li {{action "showFirst" target="App.stateManager"}} >First tab</li>
        <li {{action "showSecond" target="App.stateManager"}} >Second tab</li>
    </ul>
    <div class="tab-content" ></div>
</script>

<script type="text/x-handlebars" data-template-name="first" >
    first
</script>
<script type="text/x-handlebars" data-template-name="second" >
    second
</script>​

JavaScript:

App.stateManager = Ember.StateManager.create({
    rootElement: '.tab-content',
    initialState: 'firstTab',

    showFirst: function(manager) {
        manager.goToState('firstTab');
    },
    showSecond: function(manager) {
        manager.goToState('secondTab');
    },

    firstTab: Ember.ViewState.create({
        view: Ember.View.extend({ templateName: 'first' })
    }),
    secondTab: Ember.ViewState.create({
        view: Ember.View.extend({ templateName: 'second' })
    })
});​

Also take a look at the blog post Anatomy of an Ember.js App Part I Redux: Routing and Outlets.