2
我需要在我的网页上管理许多Web组件的全局状态。 (例如,每个Web组件都有一个“选择”按钮/功能,并跟踪组件以确保一次只选择一个组件)。如何从事件处理程序中获取对事件流的引用?
要管理我的组件的全局状态,每个Web组件都提供事件给我的主要网络应用程序中的常见处理程序。不幸的是,为了管理全局状态,我需要我的处理程序来了解它被调用的流/ web组件。我的处理程序如何获取这些信息?
这里是我的示例代码:
// _webComponents is a list of references to each component.
// getStream() gets a stream of events from each component.
// connections is a list of streams from all my web components.
_webComponents.forEach((connection)=>connections.add(connection.getStream()));
connections.forEach((Stream<String> connection)=>connection.listen(eventHandler));
void eventHandler(webComponentEvent){
// ?? How do i find out which web component the event came from ??
// ToDo: use event and web component info to manage a global state of web components.
}
非常感谢我喜欢第二个选项,它的工作很喜欢一个魅力 – 2013-05-12 19:44:23
不客气。 很高兴我能帮上忙。 – 2013-05-12 19:49:19