在新对象实例上执行的Typescript类方法

问题描述 投票:0回答:1

我正在从C#到打字稿,我想也许我正在尝试以错误的方式进行操作。

我有这个界面:

export interface OilSpillInterface {
  id?: number;
  emergenceId?: number;
  weather?: string;
  insertOilSpill?: any;
}

我有这堂课:

export default class OilSpillPrototype implements OilSpillInterface {
  id?: number;
  emergenceId?: number;
  weather?: string;

  constructor(
    emergenceId?: number,
    weather?: string){
      this.emergenceId= emergenceId;
      this.weather= weather;
    }

  insertOilSpill= async () => {
    let _iar: ItemAddResult = await sp.web.lists
      .getByTitle("Oil Spill")
      .items.add({
        emergenceId: this.emergenceId,
        weather: this.weather
      });
    return _iar.data.ID != 0;
   }
}

这就是我初始化“对象”的方式:

.
.
.
let _objOilSpill = new OilSpill(
      this.props.emergenceId,
      this.state.weather
);

console.log(_objOilSpill);

即使我不调用insertOilSpill方法,它也会执行。

我认为我正在尝试以C#方式执行此操作,但是即使我不调用它,我也不明白为什么它会执行。

我试图从接口中删除该方法,但是它以任何方式执行。

关于我在做什么错的任何提示?

typescript ecmascript-6 frontend web-parts sharepointframework
1个回答
0
投票

我发现了问题,我的组件在另一个表单组件内,父组件上的Submit事件也正在触发。

© www.soinside.com 2019 - 2024. All rights reserved.