Polymer2:纸张下拉菜单选择事件未触发

时间:2017-08-07 18:26:37

标签: javascript components polymer-2.x

我使用带有延迟负载的聚合物2启动器套件创建了应用程序。

我有一个paper-dropdown-menu,其中包含一个项目列表。此列表使用通过iron-ajax元素检索的数据。

通过iron-ajax返回的数据如下所示: ["Application 1", "Application 2", "Application 3"]

列表正确填充,但是当我点击该列表中的某个项目时,选择似乎不会在元素本身上发生变化。

selection

<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<link rel="import" href="../bower_components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../bower_components/neon-animation/web-animations.html">
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/paper-item/paper-item.html">

<link rel="import" href="shared-styles.html">

<dom-module id="my-kc">
  <template>
        <style include="shared-styles">
            :host {
                display: block;
                padding: 10px;
            }

            ul {
                list-style: none;
                padding-left: 0;
            }
        </style>

        <iron-ajax id="dbQueryIA"
                   auto
                   url="SOME URL HERE"
                   content-type="application/x-www-form-urlencoded"
                   method="POST"
                   body="[[params]]"
                   on-response="handleResponse"
                   last-response="{{response}}"
                   on-error="_confirmError">
        </iron-ajax>

        <div class="card">
          <p>Application: [[application]]</p>
          <p>Selected Item: [[selectedItem]]</p>
          <p>Selected Value: [[selectedValue]]</p>
            <paper-dropdown-menu id="applications" label="Application" placeholder="Select An Application" selected-item="[[selected]]" value="[[selectedValue]]">
              <paper-listbox slot="dropdown-content" selected="{{application}}">
                <template is="dom-repeat" items="[[response]]">
                  <paper-item value="[[item]]">[[item]]</paper-item>
                </template>
              </paper-listbox>
            </paper-dropdown-menu>
        </div>
    </template>

  <script>
    class MyKc extends Polymer.Element {
      static get is() { return 'my-kc'; }
      static get properties() {
        return {
          params: {
            type  : Object,
                    value : {
              // table: 'EAMS',
              // category: 'Admin',
              // tool: 'EAMS',
              tools: true
              //sub_category: 'Access',
              // issue: 'Account Register'
                    }
          },
          body       : Object,
          response   : Object,
          selections : {
            type: Object,
            value: function() { return {}; }
          },
          application: {
            type: String,
            value: "1"
          },
          selectedItem: {
            type: String,
            value: ""
          },
          selectedValue: {
            type: String,
            value: ""
          },
        };
      }

      static get observers() {
        return [
          '_selectionChanged(selections.*)'
        ];
      }

      _appChanged( data ) {
        debugger;
      }

      handleResponse( res ) {
        this.response = this.response.sort();
        }

        _confirmError( err ) {
            console.error( err );
        }

      _selectionChanged( selection ) {
        let value;

        if ( selection === 'application') {
          value = this.selections.application ? selection.application : 'Select an application';
        }
        console.log(value);
        return value;
      }
    }

    window.customElements.define(MyKc.is, MyKc);
  </script>
</dom-module>

1 个答案:

答案 0 :(得分:1)

缺少<link rel="import" href="../bower_components/paper-lisbox/paper-listbox.html">导入:)

http://plnkr.co/edit/QZPBbYZTROOBv1a4kftV?p=preview