我生成了一个示例Polymer web项目。添加了以下js文件。
jslib.js
function testfunction()
{
alert("test");
}
在clickcounter.dart中我添加了依赖
import 'package:js/js.dart' as js;
并更改了increment()函数
void increment() {
js.context.testfunction();
count++;
}
在clickcounter.html中添加了js文件导入
<script src="jslib.js" type="text/javascript"></script>
在主html文件中添加了
<script src="packages/browser/interop.js"></script>
在Dartium中执行时,它可以正常工作。 当我将其编译为javascript时,它会出错
Uncaught NoSuchMethodError : method not found: 'Symbol("testfunction")'
Receiver: Instance of 'Proxy'
Arguments: [] js_helper.dart:870
Stack Trace:
Error
at Object.wrapException (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:4632:13)
at Proxy.Object.noSuchMethod$1 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:33708:13)
at Proxy_noSuchMethod_closure.call$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109612:46)
at Object.Proxy.static.Proxy__forward (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109581:45)
at Proxy.noSuchMethod$1 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:109492:14)
at Proxy.Object.testfunction$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:56090:17)
at ClickCounter.increment$0 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:7080:50)
at CachedInvocation.invokeOn$2 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:6221:28)
at JsInstanceMirror._invoke$4 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:12998:35)
at JsInstanceMirror.invoke$3 (http://127.0.0.1:3030/testrun/out/web/testrun.html_bootstrap.dart.js:12963:17)
答案 0 :(得分:0)
尝试将interop.js
的引用置于已编译的dart文件和dart.js
的引用之上:
<script type="text/javascript" src="path/to/interop.js"></script>
<script type="text/javascript" src="path/to/main.dart.js"></script>
<script type="text/javascript" src="path/to/dart.js"></script>
我从Dart Issue # 15065学到了这一点,它解决了我对dart:js库的类似错误。