我想在 JavaScript 中将 Polymer paper-dropdown-menu 重置为初始状态,因此没有选择任何内容,所以它看起来像这样:
我可以在 paper-dropdown-menu 内的 paper-menu 标签中添加一个 id 并在 JavaScript 中访问它并选择它的选定索引:
document.getElementById("accountTypeMenu").selected = 1;
但是,我只能选择一个可用的项目,因此该数字需要为 0 或更大。我无法将其设置为 -1 以不选择任何内容以直观地将其返回到初始状态,但我可以将所选状态记录为我刚刚设置的状态。我尝试更改的其他值选择为空且未定义。
这是我用于纸张下拉菜单的 html:
<paper-dropdown-menu
id="accountTypeDropdown"
selected-item="{{selectedItem}}"
selected-item-label="{{selected}}"
label='*Account type'
style="width:50%;"
noink
no-animations>
<paper-menu id="accountTypeMenu"
class="dropdown-content"
onmouseup="requiredMenuFieldSelected('accountType')">
<template is="dom-repeat"
items="{{accountTypes}}"
as="accountType">
<paper-item value="[[accountType.id]]">[[accountType.name]]</paper-item>
</template>
</paper-menu>
</paper-dropdown-menu>
<input is="iron-input"
name="accountType"
type="hidden"
value$="[[selectedItem.value]]">