问题
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