你可以这样做:(使用我派生的Bootstrap.Tabs实现)
{{#view Bootstrap.TabContainerView currentView="patient"}}
<ul class="nav nav-tabs">
{{#view Bootstrap.TabView value="patient"}}<a>Patient</a>{{/view}}
{{#view Bootstrap.TabView value="visits"}}<a>Visits</a>{{/view}}
{{#view Bootstrap.TabView value="contacts"}}<a>Contacts</a>{{/view}}
{{#view Bootstrap.TabView value="sessions"}}<a>Sessions</a>{{/view}}
</ul>
{{#view Bootstrap.TabPaneView viewName="patient"}}
{{render "patient"}}
{{/view}}
{{#view Bootstrap.TabPaneView viewName="visits"}}
{{render "visits"}}
{{/view}}
{{#view Bootstrap.TabPaneView viewName="contacts"}}
{{render "contacts"}}
{{/view}}
{{#view Bootstrap.TabPaneView viewName="sessions"}}
{{render "sessions"}}
{{/view}}
{{/view}}
或使用路由器:
<ul class="nav nav-tabs">
{{#view Bootstrap.TabItem item="patient"}}
{{#linkTo "tab.patient" content}}Patient{{/linkTo}}
{{/view}}
{{#view Bootstrap.TabItem item="visits"}}
{{#linkTo "tab.visits" content}}Visits{{/linkTo}}
{{/view}}
{{#view Bootstrap.TabItem item="contacts"}}
{{#linkTo "tab.contacts" content}}Contacts{{/linkTo}}
{{/view}}
{{#view Bootstrap.TabItem item="sessions"}}
{{#linkTo "tab.sessions" content}}Sessions{{/linkTo}}
{{/view}}
</ul>
{{outlet}}
魔术是由 Bootstrap.TabItem 完成的,它从 linkTo 助手获取活动状态
Bootstrap.TabItem = Ember.View.extend({
tagName: 'li',
classNameBindings: ['active'],
activeChanged: function () {
var self = this;
Ember.run.next(this, function () { //delay
if (!self.isDestroyed) {
self.set('active', self.get('childViews.firstObject.active'));
}
});
}.observes('childViews.firstObject.active') //get the active state from the linkTo helper
});
现在您只需要一个路由器,如下所示:
App.Router.map(function (match) {
...
this.resource('tab', { path: '/tab' }, function () {
this.route('patient');
this.route('visits');
this.route('contacts');
this.route('sessions');
});
...
});
一个 jsFiddle 可能会有所帮助