从JavaScript获取变量到Dart [英] Get variable from JavaScript into Dart

查看:115
本文介绍了从JavaScript获取变量到Dart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript库被导入我的HTML文档头。如何从此库中访问对象?



谢谢。

解决方案

p> JavaScript的互操作在文章'使用JavaScript from Dart:the js Library'



简而言之,您必须:

  //导入JS互操作库
import'package:js / js.dart'as js;

//访问页面的JS上下文
var context = js.context;

//然后使用上下文来访问JS对象
var canvas = query('#map_canvas');
var googlemaps = js.context.google.maps;

//并创建通过代理访问的JS对象
var googlemap = new js.Proxy(googlemaps.Map,canvas);

有关详细信息(范围,生命周期,回调等)和示例, / p>

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

Thank you.

解决方案

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.

这篇关于从JavaScript获取变量到Dart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆