聚合物,vaadin-combo-box;获取输入值

Polymer, vaadin-combo-box; Get value of input

我正在尝试获取 vaadin 组合框输入的值,但 returns [object Object]。我无法找到如何获取输入的实际值,我的表单将包含大约三个。请告诉我在读取 vaading-combo-box 的值时我做错了什么。

这是我的代码:

<link rel="import" href="../bower_components/polymer/polymer-element.html">
<link rel="import" href="../bower_components/paper-input/paper-input.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/iron-form/iron-form.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">

<link rel="import" href="../bower_components/vaadin-combo-box/vaadin-combo-box.html">



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

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

    <div class="card">
<iron-ajax
    id="ajax"
    url="http://localhost/data.php"
    params=''
    handle-as="text"
    on-response="hresponse"
    debounce-duration="300"></iron-ajax>

<paper-input label="Name" id="thename" name="thename"></paper-input>
<iron-ajax url="https://api.myjson.com/bins/1b0f7h" last-response="{{response}}" auto></iron-ajax>
     <vaadin-combo-box name="fromm" id="fromm" items="[[response]]" item-value-path="fromm" label="fromm" item-label-path="countryName">
       <template>
           <paper-item-body two-line>
             <div>[[item.countryName]]</div>
           </paper-item-body>
       </template>
     </vaadin-combo-box>

 <button on-click="setajax">Click me</button>


  </div>
  </template>


  <script>
      Polymer({
          is: "my-view2",
          setajax: function () {
            alert(this.$.thename.value);

      //    alert(this.$.fromm.value); not working - returns Object object



          //   this.$.ajax.params = {thename:this.$.thename.value, fromm:this.$.fromm.value};
          //   this.$.ajax.generateRequest();
          },
          hresponse: function(request) {
              console.log(request.detail.response);
              console.log(this.$.ajax.lastResponse);
          }
      });
  </script>
</dom-module>

我可以用 alert(this.$.thename.value) 提醒 Name 的值,但是当我尝试对 from 的值 alert(this.$.fromm.value) 做同样的事情时,它总是 returns [object Object]

您在 vaadin-combo-box 中的 item-value-path="fromm" 引用了值为 response 对象的组合框。这就是它向您展示 [object Object].

的原因

item-value-path的值改成你想显示的。

例如,如果您的对象是

response:[{name:"Whosebug", countryName:"Australia"}]

如果要显示countryName的值,就输入item-value-path="countryName"