Marionette bubble event from itemview to parent layoutview?

前端 未结 5 1659
面向向阳花
面向向阳花 2021-02-08 17:10

I have a layout view with a region, in that region I have a item view that triggers an event but it doesn\'t seem to be bubbled up to the layout view. Am I doing something wron

5条回答
  •  长发绾君心
    2021-02-08 18:00

    Why not just allow the click event to bubble up the DOM hierarchy and handle it in your Layout view? Something like this (fiddle here):

    var MainView = Marionette.Layout.extend({
        template: "#layout-template",
        regions: {
            childRegion: "#childRegion"   
        },
        events: {
            'click #btn': 'handleButtonClick'   
        },
        handleButtonClick: function() {
           alert('btn clicked in child region and bubbled up to layout');
        }
    });
    
    var ChildView = Marionette.ItemView.extend({
        template: "#child-template"
        /*
        triggers: {
            "click #btn": "btn:clicked"   
        }*/
    });
    

提交回复
热议问题