ItemView触发器会起泡吗? [英] Do ItemView triggers bubble up?

查看:80
本文介绍了ItemView触发器会起泡吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子的CompositeView.我在子项ItemView中为每一行设置了触发器...

I have a CompositeView for a table. I have triggers set in the child ItemView for each row...

var TableRow = Marionette.ItemView.extend({
    tagName: "tr",
    template: _.template($(TableTemplates).filter('#tableRow').html()),
    triggers: {
        "click td": "click:td"
    }
});

触发器是否应该出现在父级CompositeView上?

Are the triggers supposed to bubble up to the parent CompositeView?

来自文档 ...

具有访问这些[触发事件的视图的视图,模型和集合属性]的权限,可以更灵活地处理来自多个视图的事件.例如,选项卡控件或展开/折叠小部件(如面板栏)可以从许多不同的视图触发相同的事件,并可以通过单个功能进行处理.

Having access to these [the view, model, and collection properties of the view that triggered the event] allows more flexibility in handling events from multiple views. For example, a tab control or expand/collapse widget such as a panel bar could trigger the same event from many different views and be handled with a single function.

单个功能"是否不在父CompositeView中,以便它可以对任何子ItemViews的触发器做出反应? CompositeView如何侦听ItemView触发器?

Wouldn't the "single function" be within the parent CompositeView so that it can react to the triggers from any of its child ItemViews? How does the CompositeView listen for the ItemView trigger?

谢谢

推荐答案

是的,它们冒泡了.

唯一要记住的是,当从CompositeViewCollectionView调用ItemView时,该触发器将在名称前加上itemview,因此:

The only thing to have in mind is that when an ItemView is called from a CompositeView or CollectionView, that trigger will have itemview prepended in the name, so:

click:td将在CompositeView中作为itemview:click:td

该字符串可以像这样更改:

That string can be changed like this:

var CV = Marionette.CollectionView.extend({
  itemViewEventPrefix: "some:prefix"
});

所以您的触发器将是some:prefix:click:td

编辑:在较新的版本(不确定起始版本)上,前缀itemview已更改为childview

On newer versions (not sure about the starting version), the prefix itemview has been changed to childview

更多信息在这里:

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆