0

I have an ItemView like this:

var Userview= Marionette.ItemView.extend({
        template: "#user1",
        el: "#imp1"    
});

Question: Does this mean that template of ItemView: #user1 will go into the (say) div with id=imp1 in the DOM, when rendered?

(If not, then I guess I can use regions to render Userview in a certain div in the DOM, so its fine!)

Now, in case of rendering a CompositeView, I use Region1.show() for CompositeView. In this case, how can I render a (childView) ItemView of the CompositeView at a specific location (say a div with an id) in the DOM.

(As I am calling Region1.show() on the CompositeView and not on the ItemView, I dont know how to render the ItemView at a specific location on the DOM)

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
Vijay Singh
  • 277
  • 1
  • 3
  • 15

2 Answers2

1

So, the trick is to define a childViewContainer: "#some_id" inside the CompositeView definition. It will define location of the (childView) itemView.

Also, using the word itemView inside CompositeView will cause an error, we need to use
childView: child_view_name

Vijay Singh
  • 277
  • 1
  • 3
  • 15
1

If the ItemView is the CompositeView child, then you cannot render that at a specific location in the DOM. You can only render on a specific location inside the CompositeView(childViewContainer), and the CompositeView will render directly into DOM via a region.

So, if you want to render an ItemView at a specific location in the DOM, you should use only a Region and the ItemView, without compositeView.

var myView = new MyView();
myRegion.show(myView);
Tiberiu Popescu
  • 4,486
  • 2
  • 26
  • 38