Let's say I have an App.Page model, an ArrayController App.Page, and an App.PageView to render each App.Page.
I am trying to figure out how best to implement App.MyPagesView so that it works like this:
- if App.showAllPages is true : I want MyPagesView to contain App.PageView to display each of App.Page in App.pages
- Else : I want MyPagesView to show only one App.PageView associated with App.pages.currentPage.
The simplest implementation that comes up with me is to use a template like this:
// MyPagesViewApproach1
{{
{{view App.PageView pageBinding="pages.currentPage"}}
{{else}}
{{
{{view App.PageView pageBinding="this"}}
{{/each}}
{{/unless}}
, showAllPages? , emberJS .
PageView . PageView / PageViews DOM, .
App = Ember.Application.create({
showAllPages: false,
pages: Ember.ArrayController.create({
content: []
currentPage: null
}),
ready: function () {
this.pages.pushObject(App.Page.create({title: 'Page One'});
this.pages.pushObject(App.Page.create({title: 'Some Other Page'});
this.pages.pushObject(App.Page.create({title: 'Grrreatest Page Evar'});
this.pagesController.set('currentPage',
this.pagesController.get('firstObject'));
}
});
App.Page = Ember.Object.extend({
title: null
});
App.PageView = Ember.View.extend({
templateName: 'page',
page: null
});
App.MyPagesView_Approach1 = Ember.View.extend({
pagesBinding: 'Elicitation.pages'
});
App.MyPagesView_Approach2 = Ember.ContainerView.extend({
});
HTML:
<script type="text/x-handlebars" data-template-name="page">
The title of this page is {{ page.title }}
</script>
{{view App.MyPagesView }}
, EmberJS-y MyPagesView, App.showAllPages ?
- ContainerView? if/else, ? - ? , EmberJS, elluding .