简体   繁体   English

如何在 ReteJs 中发出自定义事件?

[英]How to emit custom event in ReteJs?

I need to emit custom events in ReteJS, how can I do it?我需要在 ReteJS 中发出自定义事件,我该怎么做?

I have googled quite a bit before finding the way out of this.在找到解决方法之前,我已经搜索了很多。 If you want to listen/trigger custom event you need to first register it to the editor with "bind" command, then you can listen for it or trigger it with some payload.如果您想监听/触发自定义事件,您需要先使用“bind”命令将其注册到编辑器,然后您可以监听它或使用一些有效负载触发它。

Related documentation link (unfortunately at least now, it says nothing about custom events binding or triggering the events) https://rete.js.org/#/docs/events相关文档链接(不幸的是,至少现在,它没有说明自定义事件绑定或触发事件) https://rete.js.org/#/docs/events

That's how:这就是如何:

  // bind - enable new event type be be triggered/listened
  editor.bind('nodeupdated');

  // start listen for event, you may pass in several events separate with space: "event1 event2 event3"
  editor.on('nodeupdated', (data) => {
    console.log(`#202114585959280 nodeupdated:: `, data);
  });

  // trigger event with some payload
  editor.trigger('nodeupdated', {foo: 'bar'});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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