There are two ways to implement a tab bar.
If you want your bookmarks to be classified, you must implement them using Router:
Patterns
<script type="text/x-handlebars" data-template-name="application"> <div class="tabpanel"> <div class="tabs"> <div {{action "goToFirstTab"}}>First tab</div> <div {{action "goToSecondTab"}}>Second tab</div> </div> {{outlet}} </div> </script> <script type="text/x-handlebars" data-template-name="firstTab"> First Tab content </script> <script type="text/x-handlebars" data-template-name="secondTab"> Second Tab content </script>
The code
var App = Ember.Application.create(); App.ApplicationController = Ember.Controller.extend(); App.ApplicationView = Ember.View.extend(); App.FirstTabView = Ember.View.extend({templateName: "firstTab"}); App.FirstTabController = Ember.Controller.extend(); App.SecondTabView = Ember.View.extend({templateName: "secondTab"}); App.SecondTabController = Ember.Controller.extend(); App.Router = Ember.Router.create({ root: Ember.Route.extend({ goToFirstTab: Ember.Route.transitionTo("firstTab"), goToSecondTab: Ember.Route.transitionTo("secondTab"), index: Ember.Route.extend({ route: "/", redirectsTo: "firstTab" }), firstTab: Ember.Route.extend({ route: "/firstTab", connectOutlets: function (router) { router.get('applicationController').connectOutlet('firstTab'); } }), secondTab: Ember.Route.extend({ route: "/secondTab", connectOutlets: function (router) { router.get('applicationController').connectOutlet('secondTab'); } }) }) }); App.initialize(App.Router);
The second way, without a router.
Templates (note that action goals have changed)
<script type="text/x-handlebars" data-template-name="application"> <div class="tabpanel"> <div class="tabs"> <div {{action "goToFirstTab" target="controller"}}>First tab</div> <div {{action "goToSecondTab" target="controller"}}>Second tab</div> </div> {{outlet}} </div> </script> <script type="text/x-handlebars" data-template-name="firstTab"> First Tab content </script> <script type="text/x-handlebars" data-template-name="secondTab"> Second Tab content </script>
The code (almost the same, except that the code associated with the tabs is now moved to the ApplicationController.
var App = Ember.Application.create(); App.ApplicationView = Ember.View.extend(); App.Router = Ember.Route.create(); App.FirstTabView = Ember.View.extend({templateName: "firstTab"}); App.FirstTabController = Ember.Controller.extend(); App.SecondTabView = Ember.View.extend({templateName: "secondTab"}); App.SecondTabController = Ember.Controller.extend(); App.ApplicationController = Ember.Controller.extend({ view: App.FirstTabView.create(), goToFirstTab: function () { this.connectOutlet("firstTab"); }, goToSecondTab: function () { this.connectOutlet("secondTab"); } }); App.initialize(App.Router);
tokarev
source share