2017-05-08 59 views
1

我對聚合物有點新,並沒有完全瞭解這裏發生了什麼。我正在嘗試創建一個簡單的表單頁面。這是代碼:聚合物 - 聽衆方法未定義

<dom-module id="sams-add-student"> 
    <template > 
    <div class="vertical-section"> 
     <paper-button on-click="addstudent">SUBMIT</paper-button> 
    </div> 
    </template> 

    <script> 
    (function() { 
     'use strict'; 

     Polymer({ 
     is: 'sams-add-student', 

     properties: { 
      item: { 
      type: Object 
      }, 
      addstudent: function (event) { 
      console.log('addstudent'); 
      } 
     } 

     }); 
    })(); 
    </script> 

</dom-module> 

但是,我收到一個錯誤,未能定義偵聽器方法。我錯過了什麼嗎?

回答

1

您錯誤地在properties內錯誤地聲明瞭addstudent方法,該方法實際上應該位於對象頂層的properties之外。

Polymer({ 
    is: 'sams-add-student', 

    properties: { 
    // addstudent: function() {...} // DON'T DO THIS HERE 
    }, 

    addstudent: function() {...} // DO THIS HERE 
} 

codepen

+0

非常感謝,這解決了這個問題。我怎樣才能訪問輸入值? –

+0

@DryHouse沒問題:)隨意問一下輸入值是一個新問題,這樣有人可以提供答案來幫助你。 – tony19

0

如果是紙輸入,你可以使用類似:

this.$.IDofyourelement.value; 
相關問題