Last active
December 15, 2015 19:29
-
-
Save belackriv/477d5c1673ea46fbcf23 to your computer and use it in GitHub Desktop.
Dynamic Tabs Layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TabOneContentView = Marionette.LayoutView.extend({ | |
template: '#viewOne' | |
}); | |
var TabTwoContentView = Marionette.LayoutView.extend({ | |
template: '#viewTwo' | |
}); | |
var TabItemView = Marionette.ItemView.extend({ | |
template: '#itemView', | |
triggers:{ | |
'click': 'show:tab:content' | |
} | |
}); | |
var TabListView = Marionette.CollectionView.extend({ | |
childView: TabItemView | |
}); | |
var MainLayoutView = Marionette.LayoutView.extend({ | |
el: '#layout', | |
template: false, | |
regions:{ | |
tabs: '#tabs', | |
content: '#content' | |
}, | |
onRender(){ | |
this.showChildView('tabs', new TabListView({ | |
collection: this.collection | |
})); | |
}, | |
onChildviewShowTabContent(childview, args){ | |
var viewFn = childview.model.get('view'); | |
this.showChildView('content', new viewFn()); | |
} | |
}); | |
var tabsCollection = new Backbone.Collection([ | |
new Backbone.Model({ | |
title: 'Tab 1', | |
view: TabOneContentView | |
}), | |
new Backbone.Model({ | |
title: 'Tab 2', | |
view: TabTwoContentView | |
}) | |
]); | |
var layout = new MainLayoutView({ | |
collection: tabsCollection | |
}); | |
layout.render(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="layout"> | |
<div id="tabs"></div> | |
<div id="content"></div> | |
</div> | |
<script type="text/template" id="viewOne">View One</script> | |
<script type="text/template" id="viewTwo">View Two</script> | |
<script type="text/template" id="itemView"> | |
<%= title %> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment