dart动态元素中的数据属性



我正在使用等代码动态创建一些html元素

new ButtonElement()

并且很容易添加之类的类

  ..classes.add('dropdown-menu')

我想添加以下html到它

data-toggle="dropdown"

但dart不允许我这么做。如果我添加一个类似的new ElementHtml

new ElementHtml('<button data-toggle="dropdown"></button>')

它说它是无效的。我需要它作为我的战利品下拉选择器。

对此有什么想法吗?

我认为您需要一个启用了data-toggle属性的NodeValidator(另请参阅Dart,为什么使用innerHtml设置影子根内容有效,而appendHtml不起作用?)

没有NodeValidator你能做的就是

new ButtonElement()..dataset['toggle'] = 'dropdown';

最新更新