新需求不接旧需求不改 2021-01-09 17:23 采纳率: 0%
浏览 25

ES6 map函数用不来,希望大佬可以帮忙用map帮忙转换一下这个if,想有个例子可以学习一下

for (let i = 0; i < this.dataSourecArry.length; i++) {
        if (this.dataSourecArry[i].checked) {
          if (this.dataSourecArry[i].label == "产废企业") {
            const ps = this.cfqy
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "经营企业") {
            const ps = this.jyqy
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "危险废物") {
            const ps = this.wastePs1
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "一般固废") {
            const ps = this.wastePs2
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "工业污泥") {
            const ps = this.wastePs3
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "医疗废物") {
            const ps = this.wastePs4
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "经营-危险废物") {
            const ps = this.wastePs5
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "经营-一般固废") {
            const ps = this.wastePs6
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          if (this.dataSourecArry[i].label == "经营-工业污泥") {
            const ps = this.wastePs7
            if (ps.length > 0) {
              this.addData(this.dataSourecArry[i].id, ps)
            }
          }
          console.log(this.dataSourecArry)
        } else {
          this.$refs.actionDate[
            this.dataSourecArry[i].id
          ].cesiumObject.entities.removeAll()
        }
      }
  • 写回答

4条回答 默认 最新

  • 放风喽 2021-01-09 18:04
    关注
    var array = [1,2,3]
    function  fangfa(canshu){
        console.log(casnhu)
    }
    // 定义一个方法,这个方法需要一个参数。
    array.map(fangfa)
    
    // 你要的东西
    function ceshi(item){
        if (item.checked) {
              if (item.label == "产废企业") {
                const ps = this.cfqy
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "经营企业") {
                const ps = this.jyqy
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "危险废物") {
                const ps = this.wastePs1
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "一般固废") {
                const ps = this.wastePs2
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "工业污泥") {
                const ps = this.wastePs3
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "医疗废物") {
                const ps = this.wastePs4
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "经营-危险废物") {
                const ps = this.wastePs5
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "经营-一般固废") {
                const ps = this.wastePs6
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              if (item.label == "经营-工业污泥") {
                const ps = this.wastePs7
                if (ps.length > 0) {
                  this.addData(item.id, ps)
                }
              }
              console.log(this.dataSourecArry)
            } else {
              this.$refs.actionDate[
                item.id
              ].cesiumObject.entities.removeAll()
            }
    }
    
    this.dataSourecArry.map(ceshi)
    评论

报告相同问题?

悬赏问题

  • ¥15 静电纺丝煅烧后如何得到柔性纤维
  • ¥15 (标签-react native|关键词-镜像源)
  • ¥100 照片生成3D人脸视频
  • ¥15 伪装视频时长问题修改MP4的时长问题,
  • ¥15 JETSON NANO
  • ¥15 VS开发qt时如何在paintgl函数中用pushbutton控制切换纹理
  • ¥20 关于 openpyxl 处理excel文件地问题
  • ¥15 MS中不知道高分子的构型怎么构建模型
  • ¥60 QQOP数据,什么是op数据号,怎么提取op数据!能不能大量提取(语言-c语言)
  • ¥15 matlab代码 关于微分方程和嵌套的分段函数。