我正在尝试从Bootstrap迁移到Polymer / Paper,在很多情况下,我必须启用/禁用以前作为ButtonElements访问的按钮,然后禁用.disabled = true / false。
因此,例如,我有一个纸质按钮,我正在尝试通过querySelector进行访问和启用/禁用,如下所示:
PaperButton nextWeekButton = querySelector("#nextweekbutton");
nextWeekButton.disabled=!_status;
但是我得到了错误:
type 'HtmlElement' is not a subtype of type 'PaperButton' of 'nextWeekButton'.
如果尝试使用
InputElement
或ButtonElement
,则会得到相同的消息。如果我尝试将其作为HtmlElement
获得,那么我当然会获得"setter 'disabled' is not defined..."
我本来要开始使用属性设置,但是真的不应该有一种像
ButtonElement
这样的方法吗?只是要确保我没有丢失任何东西。更新:现在我正在这样做
void disableButton(Element _e, bool _status) {
if(!_status) {
_e.setAttribute("disabled","true");
} else {
_e.attributes.remove("disabled");
}
}
最佳答案
我很确定问题是在初始化Polymer之前执行了您的代码。有自定义main方法时,请参见https://stackoverflow.com/a/20982658/217408如何初始化Polymer。
关于dart - 如何以编程方式选择和禁用纸张按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29932568/