JavaScript中的Dart事件 [英] Dart events in JavaScript
问题描述
我有这个代码这里,我将其转换为Dart。问题是回调。
I have this code here, which I am converting to Dart. The problem is with the callbacks.
function stop(e) {
var node = e.target.getContainer();
node[SMap.LAYER_MARKER].style.cursor = "";
var coords = e.target.getCoords();
alert("Cílová pozice: " + coords.toWGS84(2).reverse().join(" "));
}
var signals = mapa.getSignals();
signals.addListener(window, "marker-drag-stop", stop);
我在Dart中的代码
var signals = mapa.callMethod('getSignals', []);
signals.callMethod('addListener', [context, 'marker-drag-stop', stop]);
}
stop(MouseEvent event) {
var target = event.target.callMethod('getContainer',[]);// problem
context.callMethod('alert', ['texttext']);
}
stop回调被正确调用,但我不知道该怎么办与 var node = e.target.getContainer();
行。
The stop callback is properly called, but I don't know what to do with var node = e.target.getContainer();
line. The e.target return something, but what next.
问题: mapa.callMethod('addLayer',[layer])。callMethod ('enable',[]);
语法,只有一种可能的方式来调用javascript方法。我发现它有点麻烦: - /
Side question: is mapa.callMethod('addLayer', [layer]).callMethod('enable', []);
syntax, only one posible way to call javascript methods. I find it little bit cumbersome:-/
这整个js-interop东西是有点凌乱。我无法由我自己解决它,需要在每一步后再次询问。我希望当我覆盖所有interop用例,我将能够,只是使用Dart并忘记JS。
This whole js-interop thingy is kind of messy. I'm unable to resolve it by my own and need to ask again after each step. I hope when I will cover all interop use cases, I will be able, just to use Dart and forget about JS.
推荐答案
我假设这应该做的诀窍:
I assume this should do the trick:
var target = new js.JsObject.fromBrowserObject(e)['target']
.callMethod('getContainer', []);
这篇关于JavaScript中的Dart事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!