paper-dropdown-menu / paper-listbox:如何获取请求中的值

时间:2018-01-15 12:14:47

标签: javascript polymer polymer-elements

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

<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吗?

1 个答案:

答案 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