我正在尝试在飞镖中创建自定义元素。它应该只包含2个按钮。它实际上从未在整个构建过程中实现……我在做什么错?
class GraphButton extends Element {
factory GraphButton() => new Element.tag('GraphButton');
ButtonElement colorBtn;
ButtonElement removeBtn;
GraphButton.created() : super.created() {
}
void setup(String buttonText) {
text = buttonText;
//initialize color btn
colorBtn
..id = 'colorBtn' + text
..text = "colorSelector"
..onClick.listen(
(var e) => querySelector('#output').text = id + 'button clicked!');
//initialize remove button
removeBtn
..id = 'removeBtn' + text
..text = 'X'
..onClick.listen(
(var e) => this.remove());
//add to DOM
this.children
..add(colorBtn)
..add(removeBtn);
}
}
您的代码中存在一些问题。
-
其名称中必须带有的命名规则setup(...)
未调用您添加的方法,因此未向按钮添加标题HtmlElement
也可以看看:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句