Dart events in JavaScript

纵饮孤独 提交于 2020-02-06 05:33:28

问题


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);

My code in 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']); 
}

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.

Side question: is mapa.callMethod('addLayer', [layer]).callMethod('enable', []); syntax, only one posible way to call javascript methods. I find it little bit cumbersome:-/

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.


回答1:


I assume this should do the trick:

var target = new js.JsObject.fromBrowserObject(e)['target']
  .callMethod('getContainer', []);


来源:https://stackoverflow.com/questions/28584388/dart-events-in-javascript

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