如何在Dart中监听自定义事件? [英] How do I listen for custom events in Dart?
本文介绍了如何在Dart中监听自定义事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做像
// WARNING: this code does not work, it's illustrative
query("#myBtn").onClick.listen((e) {
window.fire["foo"];
});
window.on["foo"].listen((e) => print("foo was here"));
window.on["foo"].listen((e) => print("and here"));
有可能吗?怎么样?我现在在Google上搜索了几个小时,但我对一般的编程很陌生,所以我真的不知道这样的关键字。
Is it possible? How? I've been searching on Google for a few hours now, but I'm kind of new to programming in general, so I don't really know any keywords for this sort of thing.
谢谢! :)
- 编辑:解决 -
-- Solved --
这里是如何传递参数,但它工作)
Here's how to pass arguments along (The editor will complain, but it works)
List<String> myData = ["one","two"];
query("#myBtn").onClick.listen((e) {
window.on["foo"].dispatch(new CustomEvent("foo", canBubble: false, cancelable: false, detail: myData));
});
window.on["foo"].add((e) => print( e.detail[1] ));
: - )
推荐答案
这应该可以工作:
window.on['foo'].listen((e) => print("foo was here"));
查看文档:
- http://api.dartlang.org/docs/releases/latest/dart_html/Events.html
这篇关于如何在Dart中监听自定义事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文