打字稿角度数组循环,但不循环解释

时间:2020-03-05 07:15:03

标签: angular typescript

LoadDetail(kodeGolGaji){
    this.loading = true;
    this.golonganGajiService.detailGolonganGaji(kodeGolGaji).subscribe(
      r => {
        this.loading = false;
        if (r.length) {
          this.data = r;
          console.log(r);
        } else {
          console.log("no data");
        }
      }
    )
  }
}

在订阅函数中,r变量是一个数组。 该语法是什么意思?

我没有扩展循环。 array => {code}是什么语法名称?是仅在脚本中还是6?

1 个答案:

答案 0 :(得分:0)

如果您需要在r块内循环subscribe(),请使用:

r => {
    this.loading = false;
    if (r.length) {
        r.forEach((item) => {
            // your loop
        });
        this.data = r;
        console.log(r);
    } else {
        console.log("no data");
    }
}

那个语法是什么意思?

if (r.length) {

如果数组中有项目JavaScript array length explained

this.data = r;

将数组的值分配给this.data

相关问题