Dart 如何从javascript函数返回值
我正在使用Dart中的js库访问OpenLayers。相关代码如下所示:Dart 如何从javascript函数返回值,dart,dart-js-interop,Dart,Dart Js Interop,我正在使用Dart中的js库访问OpenLayers。相关代码如下所示: js.scoped(){ ol=js.retain(js.context.OpenLayers); var max_extent=new js.Proxy(ol.Bounds,-13652354.432172,6026153.418145,-13574082.915218,6065289.1766216); var限制范围=最大范围; 如果(控件==null){ var options=js.map({ “最大范围”:最大
js.scoped(){
ol=js.retain(js.context.OpenLayers);
var max_extent=new js.Proxy(ol.Bounds,-13652354.432172,6026153.418145,-13574082.915218,6065289.1766216);
var限制范围=最大范围;
如果(控件==null){
var options=js.map({
“最大范围”:最大范围,
“受限扩展”:受限扩展,
‘单位’:‘m’,
“projection”:新的js.Proxy(ol.projection,“EPSG:900913”),
'displayProjection':新的js.Proxy(ol.Projection,'EPSG:4326'),
“控件”:js.array([new js.Proxy(ol.Control.attribute)),
新的js.Proxy(ol.Control.Navigation),
新的js.Proxy(ol.Control.ArgParser),
新的js.Proxy(ol.Control.PanPanel),
新的js.Proxy(ol.Control.ZoomPanel)
])
});
_treemap=js.retain(新的js.Proxy(ol.Map,Map\u div\u id,options));
}
var roads=新地图图层(ol,图层类型:'road')。图层;
var Aeror=新图层(ol,图层类型:'hybrid')。图层;
_treemap.addLayers(js.array([道路,空中]);
_树形图退根层(道路);
_treemap.zoomToMaxExtent();
var result=_treemap.layers();
});
除最后一行外,所有工程均按预期进行\u treemap.layers()
应该返回OpenLayer.Layer
的数组。当该行执行时,我得到一个错误:
异常:TypeError:对象[Object Array]没有方法“apply”
那么,在我的Dart代码中,从javascript函数获取/处理返回值的正确方法是什么呢?
层
是一个数组(请参阅)。因此,您应该使用:
var result=\u treemap.layers;
使用\u treemap.layers()
您试图调用层,因为它是一个函数
代码的一个侧面说明:当您使用js.map({})
时,不需要在对象树中使用js.array
或js.map
。您可以简单地给出一个类似JSON的结构
var options=js.map({
“最大范围”:最大范围,
“受限扩展”:受限扩展,
‘单位’:‘m’,
“projection”:新的js.Proxy(ol.projection,“EPSG:900913”),
'displayProjection':新的js.Proxy(ol.Projection,'EPSG:4326'),
“控件”:[new js.Proxy(ol.Control.attribute),
新的js.Proxy(ol.Control.Navigation),
新的js.Proxy(ol.Control.ArgParser),
新的js.Proxy(ol.Control.PanPanel),
新的js.Proxy(ol.Control.ZoomPanel)
])
});