Combustion007
Combustion007

Reputation: 474

How do I add child views to a ContainerView

I am following EmberJS online documentation and am uncertain about how to add child view(s) to a parent or nested child view(s) to a parent. I downloaded Ember start-up folder and working with the files. I am able to view the "MainView". It all makes sense so far but when I try to follow the online documentation with regards to views and children views, I am not able to get the child view going.

My current code:

window.App = Em.Application.create();

App.MainView = Em.View.extend({
classNames: ['mainView']
});

This is the index file code:

<script type="text/x-handlebars">
{{#view App.MainView}}
  <h1>Hello world!</h1>
{{/view}}
</script>

Code listed below is what causing me confusion.

I tried plugging in the following code to see if anything would pop on to the screen, but I am sure I am approaching it wrong. Any help on this would highly be appreciated.

var container = Ember.ContainerView.create();
container.append();

var coolView = App.CoolView.create(),
childViews = container.get('childViews');

childViews.pushObject(coolView);

Thanks.

Upvotes: 1

Views: 4592

Answers (1)

Luke Melia
Luke Melia

Reputation: 8389

I've created a jsfiddle which demonstrates the answers to your questions here: http://jsfiddle.net/6ksqd/1/

This is a very contrived example, but hopefully it will help you get the hang of it.

Upvotes: 8

Related Questions