未捕获的TypeError:this.paramSend不是函数

时间:2017-11-07 22:51:11

标签: javascript polymer

我需要帮助解决此错误,我需要传递“id1”的值 和我在addEventListener中将它们分配给param send函数的“roll”。

  

未捕获的TypeError:this.paramSend不是函数

<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>

2 个答案:

答案 0 :(得分:0)

您必须绑定您的eventHandler以保留此上下文。

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

或使用本地参考。

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

答案 1 :(得分:0)

我通过这种方式找到了解决方案,希望有人帮忙

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();  
          });
        },