Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Last active December 20, 2015 20:29
Show Gist options
  • Save knownasilya/6190792 to your computer and use it in GitHub Desktop.
Save knownasilya/6190792 to your computer and use it in GitHub Desktop.
Ember ContainerView
<script type="text/x-handlebars" data-template-name="firstForm">
First form
</script>
<script type="text/x-handlebars" data-template-name="secondForm">
Second form
</script>
<script type="text/x-handlebars" data-template-name="thirdForm">
Third form
</script>
App.FirstFormView = Ember.View.create({
templateName: 'firstForm'
});
App.SecondFormView = Ember.View.create({
templateName: 'secondForm'
});
App.ThirdFormView = Ember.View.create({
templateName: 'thirdForm'
});
{{view Ember.Select
contentBinding="content"
valueBinding="view.selectedValue"
optionValuePath="content.id"
optionLabelPath="content.value"
}}
{{view view.formsView}}
App.IndexRoute = Ember.Route.extend({
model: function(){
return [
{id: 0, value: 'Form 1' },
{id: 1, value: 'Form 2' },
{id: 2, value: 'Form 3' }
];
}
});
App.IndexView = Ember.View.extend({
selectedValue: null,
forms: [
App.FirstFormView,
App.SecondFormView,
App.ThirdFormView
],
formsView: Ember.ContainerView.create({}),
changeForm: function () {
var forms = this.get('forms'),
id = this.get('selectedValue');
this.formsView.set('currentView', forms.objectAt(id));
}.observes('selectedValue')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment