Marionette 2.4.4 LayoutView 的 childEvents 没有触发?

Marionette 2.4.4 LayoutView's childEvents not firing?

我有一个 LayoutView 可以处理显示它自己的 children。根据文档,我可以扩展 childEvents object 以自动侦听在其 child 视图上触发的任何事件。

这根本不适合我。谁能发现我可能做错了什么?

Show.QuizLayout = Marionette.LayoutView.extend({
    template:_.template("<h3><%= title %></h3><div id='quiz'></div>"),
    regions: {
        card: "#quiz",
    },
    childEvents: {
        "next:question": "showNextQuestion",
    },
    showNextQuestion:function () {
        //I NEVER GET CALLED!!!
    },
    onShow:function(){
        var v = new Show.QuizCard();
        this.showChildView('card',v)
});

Show.QuizCard = Marionette.ItemView.extend({
    className: "quizcard",
    template: _.template("<div class='card' id='next'>Next</div>"),
    events: {
        "click #next":function(e){
            this.trigger("next:question")
       }
    },
});

我已经通过设置 v.on("next:question", function(){...}) 解决了这个问题,但是如果我能让 childEvents 以他们应该的方式工作的话,它会产生我宁愿不必处理的问题.

尝试:

childEvents: {
  "next:question": this.showNextQuestion,
}

或者看看triggerMethod

运气好不好
events: {
    "click #next":function(e){
        this.triggerMethod("next:question")
   }
}

然后在您的布局中有一个名为 onChildviewNextQuestion

的方法

http://marionettejs.com/docs/v2.4.5/marionette.layoutview.html#layoutview-childevents

如文档中所述,您应该在子视图中使用 triggerMethod,而不是 trigger

childEvents also catches custom events fired by a child view. Take note that the first argument to a childEvents handler is the child view itself. Caution: Events triggered on the child view through this.trigger are not yet supported for LayoutView childEvents. Use strictly triggerMethod within the child view.