2017-09-12 7 views
0

vaadin-combo-box入力の値を取得しようとしていますが、を返します。私は入力の実際の値を取得する方法を見つけることができません、私のフォームは約3含まれます。 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)と名前の値を知らせることができますが、私はのからの値alert(this.$.fromm.value)に同じことをやろうとしているときは、常に[object Object]を返します。

答えて

2

item-value-path="fromm"vaadin-combo-boxは、値がresponseのコンボボックスを参照しています。だから、それはあなたに[object Object]を示しているのです。

item-value-pathの値を表示する値に変更します。あなたがCOUNTRYNAMEの値を表示したい場合は例えば

あなたのオブジェクトが

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

のようなものである場合には、item-value-path="countryName"を置きます。

+0

これは間違いありません。どうもありがとうございました! – unkn0wnx

関連する問題