marionette如何从ItemView中调用CompositeView函数?

marionette how to call CompositeView function from ItemView?

我在 CompositeView 中有一个函数:

Marionette.CompositeView.extend({ childView: ItemView, onCheckMask: function() { alert('hello!') }, ...

我想从 ItemView 调用这个函数:

Marionette.ItemView.extend({ ... anotherFunction: function() {//here i want to call function 'onCheckMask'...}

我该怎么做?粉丝们!

假设您已将 Marionette.CompositeView 实例化为 myCompositeView,只需在 anotherFunction();

中执行 myCompositeView.triggerMethod('check:mask');

这将在 myCompositeView 上调用 onCheckMask。可以在 Marionette docs.

中找到更多文档

总是喜欢使用事件而不是直接调用函数,帮助您解耦应用中的不同区域。