Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sooner or later want to change the naming of your states or whatever you have to go through the code AND the view as well, also adding a function to transitionTo every route seems not desirable. My approach is a bit more programmatic and modularized:</p> <pre><code># Parent View-Tamplate, holding the navbar DOM elements App.NavView = Ember.View.extend( controller: App.NavArrayController templateName: "ember-nav" ) # We push NavItems into this array App.NavArrayController = Ember.ArrayController.create( content: Ember.A([]) ) # NavItem has two settable properties and # an programmatic active state depending on the router App.NavItem = Ember.Object.extend( title: '' goto: null # &lt;=this is the name of the state we want to go to! active: (-&gt; if App.router.currentState.name == @.get "goto" true else false ).property('App.router.currentState.name').cacheable() ) # the actual NavElement which gets the class="active" if the # property "active" is true, plus a on-click binding to # make the Router transition to this state App.NavItemView = Ember.View.extend( tagName: "li" classNameBindings: ["active"] click: -&gt; App.router.transitionTo(@get('goto')) false ) </code></pre> <p>nav-view.hbs (for twitter-bootstrap-style navs)</p> <pre><code>&lt;div class="nav-collapse collapse"&gt; &lt;ul class="nav"&gt; {{#each App.NavArrayController}} {{#view App.NavItemView classBinding="active" gotoBinding="goto"}} &lt;a href="#" {{bindAttr data-goto="goto"}}&gt; {{title}}&lt;/a&gt; {{/view}} {{/each}} &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>This way, I can just create and mess around with my routes in the Router, and keep the Nav-Definitions side-by-side:</p> <pre><code># put this somewhere close to the Router App.NavArrayController.pushObjects( [ App.NavItem.create( title: 'Home' goto: 'home' ), App.NavItem.create( title: 'Chat' goto: 'chat' ), App.NavItem.create( title: 'Test' goto: 'test' ) ] ) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload