Get variable from JavaScript into Dart

僤鯓⒐⒋嵵緔 提交于 2019-12-10 20:33:42

问题


I have a JavaScript library being imported in my HTML Documents head. How can I access objects from this library?

Thank you.


回答1:


The interop with JavaScript is desribed in article 'Using JavaScript from Dart: The js Library'

In short, you have to:

//import the JS interop lib
import 'package:js/js.dart' as js;

// access the JS context for the page
var context = js.context;

// then use context to access JS object
var canvas = query('#map_canvas');
var googlemaps = js.context.google.maps;

// and create JS objects accessed through proxies
var googlemap = new js.Proxy(googlemaps.Map, canvas);

For more details (scopes, lifetimes, callbacks, etc) and examples, refer to linked article.



来源:https://stackoverflow.com/questions/16880641/get-variable-from-javascript-into-dart

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