Search code examples
javascriptuser-interfacedommarionette

DOM location of ItemView when passed in CompositeView - Marionette


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)


Solution

  • 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