微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 console.log 函数中产生 NaN

如何解决在 console.log 函数中产生 NaN

在我的项目中,我有一个 select,其中选择 type,更改函数total。问题是,如果我不先选择所有三个 typeconsole.log 中的总数会给我一个 NaN。不需要其他两种类型的结果,我如何仍然拥有总数?

type: number = 0

calcTotal() {
    this.variabileIntervento.forEach(t => {
      t.totale = []
      for (const i in t.varianti) {
        this.modcos = t.modicitaDiCosto[i] * this.ponderazione[0]
        this.effic = t.efficacia[i] * this.ponderazione[1]
        if(this.type == 1) {
          this.supInton = t.supIntonacate[i] * this.ponderazione[2]
        } 
        else if(this.type == 2) {
          this.supEv = t.supEvIi[i] * this.ponderazione[2]
        } 
        else if(this.type == 3) {
          this.supIv = t.supIvEi[i] * this.ponderazione[2]
        }
        this.revers = t.reversibilita[i] * this.ponderazione[3]
        this.semplCant = t.semplicitaDiCantiere[i] * this.ponderazione[4]
        this.esigIngom = t.esiguitaDiIngombro[i] * this.ponderazione[5]
        t.totale.push(this.modcos + this.effic + this.supInton + this.supEv + this.supIv + this.revers + this.semplCant + this.esigIngom)
      }
      console.log("Total: ",t.totale);
    })
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。