this =在typescript中的匿名函数中未定义

时间:2017-04-20 07:52:05

标签: typescript

这是一种解决方法,显然我不应该首先使用它。但是当我调试代码时 - “this”等于undefined !!!

public loadByIds(raw:string):Promise<any> {
    const _this = this;
    this.ids = raw.split('\n');
    return this.api.getStones(this.ids).then( results => {
      _this.problems.notFound = results.notFound;
      _this.problems.removed = results.removed;
      (results.accounts as Array<any>).forEach( (account:AccountFlatModel) => {
        _this.accounts.push(account);
      });
    });
  }

0 个答案:

没有答案