如何在Dart中引用dojo方法?我特别尝试使用ESRI's Javascript API,它通过引用Google's article on on javascript/Dart interoperability
在dart中构建在dojo之上<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Home Extent</title>
<link rel="stylesheet" type="text/css" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
<style>
html, body, #map {
padding:0;
margin:0;
height:100%;
}
#HomeButton {
position: absolute;
top: 95px;
left: 20px;
z-index: 50;
}
</style>
<script src="//js.arcgis.com/3.8/"></script>
<script>
require([
"esri/map",
"esri/dijit/HomeButton",
"dojo/domReady!"
], function(
Map, HomeButton
) {
var map = new Map("map", {
center: [-56.049, 38.485],
zoom: 3,
basemap: "streets"
});
var home = new HomeButton({
map: map
}, "HomeButton");
home.startup();
});
</script>
</head>
<body>
<div id="map" class="map">
<div id="HomeButton"></div>
</div>
</body>
</html>
我认为我很好地掌握了如何调用方法和转换对象,但我无法弄清楚如何调用dojo方法(特别是Dojo 1.7+ method),在这种情况下“需要”。
答案 0 :(得分:1)
使用 dart:js ,以下内容应该有效:
import 'dart:js' as js;
main() {
js.context.callMethod('require', [new js.JsArray.from(["esri/map",
"esri/dijit/HomeButton", "dojo/domReady!"]), (Map, HomeButton) {
var map = new js.JsObject(Map, ["map", new js.JsObject.jsify({
'center': [-56.049, 38.485],
'zoom': 3,
'basemap': "streets"
})]);
var home = new js.JsObject(HomeButton, [new js.JsObject.jsify({
map: map
}), "HomeButton"]);
home.callMethod('startup');
}]);
}