Event driven programming in Ext JS

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:58:03

问题


I'm working on an application where different widgets from different plugins would be loaded into a host, and they don't know of each other. So I want to use EDP and in one widget raise an event (for example, UserDeleted) and in another widget, subscribe to that event (the famous publisher/subscriber, or let's get more specific, observer pattern).

In jQuery I use trigger() and bind() methods to accomplish this. However, I'm not able to find anything equivalent in Ext JS. Am I missing something? Or is there any other pattern to create loosely coupled UI widgets in Ext JS?


回答1:


If your widgets don't know about each other, you need to use the mediator pattern.

And it seems that Ext.util.Observable is what you're looking for.




回答2:


Since ExtJS 4.x Sencha introduced the concept of Controllers which listen for events in a clean systematic pattern of an MVC application. In this scheme your components would fire events (built in or custom ) and controllers will respond to those events.

To fire a custom event you can use fireEvent method on the Observable class which is inherited by just about all other ExtJS classes.



来源:https://stackoverflow.com/questions/12932325/event-driven-programming-in-ext-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!