【问题标题】:dart2js's output causes "null is not an object"dart2js 的输出导致“null 不是对象”
【发布时间】:2014-03-18 12:29:42
【问题描述】:

运行后

private/dart/dart-sdk/bin/dart2js -m -o public/js/script.js private/dart/script.dart

生成的javascript返回

TypeError: 'null' is not an object (evaluating 'J.RE(a).gVs')

但是,未缩小的错误是

TypeError: 'null' is not an object (evaluating 'J.getInterceptor$x(receiver).get$onBlur')

这可能更有意义。

无论我使用 script.js 还是 script.compiled.js,它都会这样做。

飞镖代码是

import 'dart:html';
import 'dart:core';

void main() {
   querySelector("#authorInput").onBlur.listen(updateSurname);
}
void updateSurname(Event e){
   String author = (e.target as InputElement).value;
   String surname = author.split(' ').last;
   querySelector("#surnameInput").text = surname;
}

相关的haml是

  .form-group
     %label(for="authorInput") Author
     %input.form-control#authorInput(type="text" name="author" placeholder="Enter author")
  .form-group
     %label(for="surnameInput") Surname
     %input.form-control#surnameInput(type="text" name="surname" placeholder="Enter surname")

我相信它应该按原样工作,但显然情况并非如此。

【问题讨论】:

  • 您可以使用pub build --mode=debug 构建以禁用名称修改。然后错误消息/堆栈跟踪更有帮助。

标签: javascript dart dart2js


【解决方案1】:

想通了。

我将编译后的 javascript 文件包含在 html 页面的标记中。将它移动到身体的最底部固定了一切。

【讨论】:

    猜你喜欢
    • 2014-04-02
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2017-05-01
    相关资源
    最近更新 更多