我在纸张下拉菜单中有纸制列表框元素,项目的值与标签不同。
这是例子

<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=Mgender=F吗?

最佳答案

可以,尽管您必须向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

07-26 08:14