Here's a jsbinshowing the problem, however, it doesn't identify the error in the same way as on my computer. On my computer, I am told that Uncaught Error: childViews is immutable.
I am trying to add a childview to a containerView upon a click event, but I'm told that childviews (an array of views on containerView) are immutable. Can you explain how to add a childView to a containerView? I also tried appendChild but there's an error message that it can't be called during the rendering process.
In older versions of Ember, you used to be able to push objects onto the childViews array, for example, as this jsfiddle shows but the api appears to have changed.
If it's impossible, how to create this ui without pushing to the childViews array on a containerView?
App = Ember.Application.create({});
App.MainView = Em.View.extend({
classNames: ['mainView']
});
App.MyContainerView = Em.ContainerView.extend({});
App.AnotherView = Em.View.extend({
render: function(buffer){
buffer.push('App.AnotherView ' + this.get('elementId'));
}
});
App.AddChildViewButton = Em.View.extend({
tagName: 'button',
render: function(buffer) {
buffer.push('Add Child View');
},
click: function() {
var containerView = Em.View.views['my_container_view']
var childView = containerView.createChildView(App.AnotherView);
containerView.get('childViews').pushObject(childView);
}
});
template
<script type="text/x-handlebars" >
{{#view App.MainView}}
<h1>Hello world!</h1>
<br>
{{view App.AddChildViewButton}}
<br>
{{view App.MyContainerView elementId="my_container_view"}}
{{/view}}
</script>