[英]How to trigger a custom event in capture phase
Is there a way to trigger a custom event in javascript, so that it will propagate using the capture
model? 有没有一种方法可以触发javascript中的自定义事件,以便它可以使用
capture
模型传播?
I have a hierarchy of elements that I use as a mean to communicate between objects. 我有一个元素层次结构,用作在对象之间进行通信的手段。 Each level of the hierarchy represents a sub-family of object.
层次结构的每个级别代表对象的一个子族。 Ideally, I could trigger an event to each family's or sub-family's objects using their common ancestor.
理想情况下,我可以使用其共同祖先触发每个家庭或子家庭的对象的事件。
eg: 例如:
animals |_ | mammals | |_cats | |_dogs |_ reptiles |_alligators |_dinosaurs
(please no comments on my inadequate taxonomy :) ) (请不要对我的分类法不足发表评论:))
I would like to be able to trigger an event for all animals, all mammals or all cats, or event to a single cat instance. 我希望能够触发所有动物,所有哺乳动物或所有猫的事件,或触发单个猫实例的事件。
However, I can only find examples of custom events using the bubbling phase, so I want to know if it's me missing something or is this really impossible. 但是,我只能在冒泡阶段找到自定义事件的示例,因此我想知道是我遗漏了某些东西还是这真的不可能。
I know I can use event delegation on the root element for all instance, but it will scale really badly (this system needs to handle thousands of events of all types). 我知道我可以在所有实例的根元素上使用事件委托,但是这样做的伸缩性很差(此系统需要处理数千个各种类型的事件)。
Any ideas? 有任何想法吗?
对于当前的DOM事件规范,这是不可能的,因为它仅支持冒泡阶段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.