1

我正在尝试使用 Dart 执行地图示例。但是我收到一个错误 JsObject 类没有构造函数 jsify 我正在使用的飞镖代码是

library google_maps;

import 'dart:html' show query;
import 'dart:js' show context, JsObject;

void main() {
  // The top-level getter context provides a JsObject that represents the global
  // object in JavaScript.
  final google_maps = context['google']['maps'];

  // new JsObject() constructs a new JavaScript object and returns a proxy
  // to it.
  var center = new JsObject(google_maps['LatLng'], [-34.397, 150.644]);

  var mapTypeId = google_maps['MapTypeId']['ROADMAP'];

  // new JsObject.jsify() recursively converts a collection of Dart objects
  // to a collection of JavaScript objects and returns a proxy to it.
  var mapOptions = new JsObject.jsify({
      "center": center,
      "zoom": 8,
      "mapTypeId": mapTypeId
  });

  // Nodes are passed though, or transferred, not proxied.
  new JsObject(google_maps['Map'], [query('#map-canvas'), mapOptions]);
}

pubspec.yaml 是

name: google_maps_api_with_dart_js
description: An app that displays a location using the JavaScript
    Google Maps API that is called using the dart:js library.
dependencies:
  browser: ">=0.9.0 <0.10.0"
environment:
  sdk: ">=0.8.10+6 <2.0.0"
4

1 回答 1

1

我通过切换到新版本解决了这个问题

Dart 编辑器版本 1.0.0_r30188 (STABLE) Dart SDK 版本 1.0.0.3_r30188

现在一切正常。

谢谢!

于 2013-12-05T12:57:35.847 回答