从飞镖Element.setInnerHtml()中排除特定属性

时间:2016-08-18 19:39:03

标签: dart frontend

我遇到了以下问题:

I've encountered the following problem:

在mod之前可能会点击'复制',但事实并非如此。我已经搜索了问题,发现了“解决方案”,应用了“解决方案”而且它们无法正常工作。所以问题可能是'为什么我的'解决方案'不起作用?'或者问题可能是“实际解决方案是什么?”

负责任的代码是

querySelector("#element").setInnerHtml(some_element.outerHtml, treeSanitizer: NodeTreeSanitizer.trusted);

我做错了什么?

2 个答案:

答案 0 :(得分:0)

我发现将消毒剂应用于Element。

Element element = new Element.html('<a data-tag="value">thing</a>'), treeSanitizer: NodeTreeSanitizer.trusted)

答案 1 :(得分:0)

我最近没有回去仔细检查这是最好的方法,但我们最终建立了一个常见的NodeValidator,我们可以跟上各种自定义属性。

NodeValidator get commonValidator => _commonValidator;

/// Create a NodeValidator which passes common values.
final NodeValidator _commonValidator = new NodeValidatorBuilder.common()
  ..allowHtml5()
  ..allowInlineStyles()
  ..allowNavigation(_policy)
  ..allowImages()
  ..allowTextElements()
  ..allowElement("a", attributes: [
    "data-version",
    "data-attribute-add"])
  ..allowElement("div", attributes: [
    "data-sec"]);


foo.setInnerHtml(someOddHtml, validator: commonValidator);