我在纸张下拉菜单中有纸质列表元素,项目的值与标签不同。 这是示例
<paper-dropdown-menu label="Gender" name="gender" required error-message="Gender is required">
<paper-listbox slot="dropdown-content" attr-or-property-name="value">
<paper-item value="M">Male</paper-item>
<paper-item value="F">Female</paper-item>
</paper-listbox>
</paper-dropdown-menu>
但是在帖子中,标签被赋予而不是项目的值
想知道请求中有gender=M
或gender=F
吗?
答案 0 :(得分:0)
虽然您必须向id
添加paper-listbox
属性并稍微挖掘一下,但仍有可能:
<dom-module id="item-value-demo">
<template>
<style></style>
<paper-dropdown-menu label="Gender" name="gender" required error-message="Gender is required">
<paper-listbox id="gender" slot="dropdown-content" attr-or-property-name="value">
<paper-item value="M">Male</paper-item>
<paper-item value="F">Female</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</template>
<script>
class ItemValueDemo extends Polymer.Element {
static get is() { return 'item-value-demo'; }
ready() {
super.ready();
this.$.gender.addEventListener('selected-item-changed', e => { this._genderOption(e) });
}
_genderOption(e) {
const value = e.target.selectedItem;
if (value) {
console.log(value.attributes["value"].value);
}
}
}
customElements.define(ItemValueDemo.is, ItemValueDemo);
</script>
</dom-module>
<item-value-demo></item-value-demo>
见this pen。