简体   繁体   中英

How to prevent event bubbling for custom events in a Backbone application?

I have two views - ItemView and CardView -

In card view, I trigger a global event of ItemView as -

self.eventBus.trigger('dragEvent', {
       toId: moveToId,
       fromId: moveFromId,
       id: itemId,
       e: event
       });

This event trigger is handled by 'onDragEvent' function in ItemView as-

onDragEvent:  function(options) {
   ...     
 }

The dragEvent is bubbling up. How do I avoid it?

@muistooshort may be correct when it comes to triggering an Event module like that. However, you can stop a View event from bubbling with event.stopImmediatePropagation();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM