【发布时间】:2014-02-02 18:18:31
【问题描述】:
所以我有以下 Dart/Polymer 类:
@CustomTag('my-select-element')
class MySelectElement extends PolymerElement {
@observable int currentIndex = 1;
MySelectElement.created() : super.created() {}
void changed() {
print(currentIndex);
}
}
和匹配的 html 模板:
<template name="my-select-element">
<select on-change="{{changed}}" selectedIndex="{{currentIndex}}">
<option>Index 0</option>
<option>Index 1</option>
<option>Index 2</option>
</select>
</template>
当我点击选择元素的一个选项时,我会得到正确的索引 - 来自点击之前。 正如w3schools event attributes 告诉我的那样,这是正确的行为,我应该使用 onselect 而不是 onchange 来获取值 after 它已更改。
但是,我找不到 onselect 或 on-select 或类似的东西,当我仅通过 dart 构建选择元素时,onChange.listen 会提供所需的结果(如果不正确)。
我知道我总是可以在按下按钮后检索结果,但在这种情况下,我想在不等待的情况下做一些事情。
我只是错过了正确的关键字吗?
【问题讨论】:
-
您的 HTML 无效。应该是
<polymer-element name="my-select-element"><template><select ...></select></template></polymer-element>。 -
您的
changed()必须接受 3 个参数(事件、详细信息、目标) -
实际上,我已经 changed() 使用了 0、1 和 2 参数 - 我错过了所有重要的第三个最新元素参数:)
标签: dart dart-polymer