I am currently trying to render a child view in a parent view like so:
var ParentView = Backbone.View.extend({
initialize: function(){
this.render();
this.childView = new ChildView({el: '#id1', model: this.model.get('collection').at(index)});
},
render: function(){
this.$el.html(ich.parent_template(this.model.toJSON()));
}
}):
The parent template is fairly simple, something along the lines of:
<script id="parent_view" type="text/html">
<div>
<h1 class="section-title">{{ title }}</h1>
<div id="id1"></div>
</div>
</script>
I wanted to render the childView like so:
var ChildView = Backbone.View.extend({
initialize: function(){
this.render();
},
render: function(){
this.$el.html(ich.child_template(this.model.toJSON()));
}
}):
but when do this nothing appears. Everything works fine if I instantiate the child view without including the {el: '#id1'}, and then render it into the correct div from the parent view. I am just more confused about why it wouldn't work in the way I outlined above.
Am I totally misunderstanding what specifying the el of the child view does? I was trying to follow this response but it was not working for me at all.