backbone.js - 使用事件调度程序 vardispatcher = _.clone(Backbone.Events)
在 backbone.js
文档 中,它说:
制作一个方便的事件调度程序可以协调应用程序不同区域之间的事件: vardispatcher = _.clone(Backbone.Events)
任何人都可以解释如何实现调度程序以从一个视图到另一个视图进行通信吗?我必须将代码放在应用程序中的什么位置?
In backbone.js
documentation it says:
To make a handy event dispatcher that can coordinate events among different areas of your application: var dispatcher = _.clone(Backbone.Events)
Can anyone explain how to implement the dispatcher to communicate from one view to another? Where do I have to place the code in my app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一篇关于使用 事件聚合器。
您可能会有某种应用程序控制器对象,它将控制应用程序的流程、创建视图、模型等。这也是事件聚合器的好地方。
从我的角度来看,我认为这篇文章很好地解释了这一点。
Here is a good article about using an event aggregator.
You will probably have some kind of App Controller object, which will control the flow of the app, creating views, models, etc. This is also a good place for the event aggregator.
From my point of view, I think that article explains it pretty well.
最近,我需要一个 EventDispatcher 来处理大量事件,而又不会丢失它们的名称和行为。
也许它对你也有帮助。
这是一个简单的示例视图:
这里是带有一些示例事件的 EventDispatcher。事件本身是在模板对象中预定义的。您的 IDE 应该能够识别它们并引导您完成列表。
如您所见,调度程序自行运行。只有您的视图或其他任何东西需要来自 Backbone 的底层事件方法。
Backbones 事件系统的行为不会受到任何影响,可以正常使用。
Recently I needed an EventDispatcher to handle a large amount of events without loosing track of their names and their behave.
Perhaps it helps you too.
Here a simple example View:
Here the EventDispatcher with some example events. The events itself are predefined in the template Object. Your IDE should recognize them and lead you through the list.
As you can see, the Dispatcher run on its own. Only your View or whatever needs underlying Event methods from Backbone.
The behavior of Backbones Event-system is not affected in any way and can be used as normal.