2017-11-07 3 views
0

私はこのエラーで助けが必要です。私はaddEventListener、param sendに "id1" と "roll"の値を渡す必要があります。関数。あなたは、このコンテキストを維持するために、あなたなeventHandlerをバインドする必要がUncaught TypeError:this.paramSendは関数ではありません

Uncaught TypeError: this.paramSend is not a function

<script> 
    (function() { 
     'use strict'; 
     Polymer({ 
     is: 'pa-adminuser', 
     properties: { 
      id1: { 
      type: String, 
      value: '0', 
      notify: true 
      }, 
      hide: { 
      type: Boolean, 
      value: true 
      }, 
      roll: { 
      type: String, 
      value: '0', 
      notify: true 
      } 
     }, 
     aftersave: function(){ 
      this.$.themed.addEventListener('after-save', function(e) { 
       this.id1= e.detail.row.id; 
       this.roll= e.detail.row.roll; 
       console.log('paramSend1:' + JSON.stringify({ id: this.id1, roll: this.roll })); 
       this.paramSend(this.id1, this.roll) 
      }); 
     }, 
     paramSend: function(id2, roll2){ 
      this.PostData1.body = JSON.stringify({ id: id2, roll: roll2 }); 
      this.PostData1.generateRequest(); 
      this._updateData(); 
     }, 
     _updateData: function() { 
      console.log('UPDATE DATA'); 
      this.async(function() { 
      //this.$.PostData1.generateRequest(); 
      this.$.GetData3.generateRequest(); 
      console.log('GENERATE REQUEST'); 
      }, 2000); 
     }, 
     ready: function() { 
     } 
     }); 
    })(); 
    </script> 

答えて

0

this.$.themed.addEventListener('after-save', function(e) { 
    .... 
    this.paramSend(..) 
}.bind(this)); 

またはこの地域のローカルを使用してください。

var _self = this; 
this.$.themed.addEventListener('after-save', function(e) { 
    .... 
    _self.paramSend(..) 
}); 
+0

感謝を役に立てば幸い、解決策にこの方法を見つけました –

0

私は誰かが私は同じ結果を得る2つのオプションが、答えを

aftersave: function(){ 
      var _self = this; 
      this.$.themed.addEventListener('after-save', function(e) { 
       _self.id1= e.detail.row.id; 
       _self.roll= e.detail.row.roll; 
       console.log('paramSend1:' + JSON.stringify({ id: this.id1, roll: this.roll }));    
       _self.paramBody = JSON.stringify({ id: this.id1, roll: this.roll }); 
       _self.$.PostData1.body = _self.paramBody; 
       _self.$.PostData1.generateRequest(); 
      }); 
     }, 
関連する問題