gpt4 book ai didi

dart - Dart Polymer:当编译为JS时,从DOM中删除元素似乎已损坏?

转载 作者:行者123 更新时间:2023-12-03 03:46:49 25 4
gpt4 key购买 nike

我正在尝试从DOM中删除元素,该元素是通过以下方式添加的:

document.body.children.add(new DivElement()..innerHtml = "Hello World");

编码

document.body.children.remove(document.body.children.last);

要么

document.body.children.removeLast();

在Dartium中可以正常工作,但在使用“断言失败”-错误编译为JS时在Chrome中无法运行。失败的断言为: assert(node instanceof Node);,并放置在shadow_dom.debug.js:3364:5中。看来要删除的节点不是Node的实例?

有什么解决方法吗?
Dart SDK版本是1.2.0,Chrome版本是32.0.1700.76 m。

最佳答案

来自jmesserly的bug:

Ah, this is a known limitation from Shadow DOM. Try:

document.querySelector('body')

Unfortunately, from previous bugs filed on https://github.com/polymer/ShadowDOM it is apparently not possible to fix this in the polyfill.

The only problematic members are directly accessing "document" and navigating the tree. As soon as you call a method (like querySelector), anything after that will work. If you use "body" a lot, then try:

final body = document.querySelector('body');

关于dart - Dart Polymer:当编译为JS时,从DOM中删除元素似乎已损坏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22908551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com