2

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

<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在请求中?

4

1 回答 1

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>

见此

于 2018-01-18T19:42:09.367 回答