{ "title": "r: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "undefined"/** 修改按钮操作 */ handleUpdate(row) { console.log(this.selection, "sssss"); if (!this.selection || this.selection.length === 0) { this.$message.warning("请先选中要修改的数据项"); return; } const id = row ? row.chiId : this.selection[0].chiId; // if (isNaN(id)) { // this.$message.warning("请先选中要修改的数据项"); // return; // } getReportingCmHealthInsure(id).then((response) => { this.data = response.data; this.acTaxPiIncomeReportingMedicalInsuranceList = response.data.acTaxPiIncomeReportingMedicalInsuranceList; // this.$nextTick(() => { // if (this.$refs.submitDialog) { // this.$refs.submitDialog.handleWrite.call(this, row); // } else { // console.error("submitDialog ref is not found"); // } // }); this.open = true; this.title = "商业健康保险明细编辑"; }); }, handleSelectionChange(selection) { this.selection = selection; console.log(selection, "selectionsss"); },为什么会拿不到 选中的那一行selection的chiId 怎么解决 内容:根据提供的代码,可以看到handleUpdate方法中有以下几个问题:

  1. 在获取id时,如果row不存在,则直接使用this.selection[0].chiId,但是并没有判断this.selection是否存在或者长度是否为0。如果this.selection不存在或者长度为0,会导致undefined传递给id,从而引发类型转换错误。
  2. getReportingCmHealthInsure方法中获取数据后,通过response.data赋值给this.data,但是没有判断response.data是否存在。如果response.data不存在,会导致后续的代码出错。

为了解决这些问题,可以按照以下方式修改代码:

handleUpdate(row) {
  if (!this.selection || this.selection.length === 0) {
    this.$message.warning(\"请先选中要修改的数据项\");
    return;
  }

  let id;
  if (row) {
    id = row.chiId;
  } else if (this.selection && this.selection.length > 0) {
    id = this.selection[0].chiId;
  }

  if (!id) {
    this.$message.warning(\"请先选中要修改的数据项\");
    return;
  }

  getReportingCmHealthInsure(id).then((response) => {
    if (response.data) {
      this.data = response.data;
      this.acTaxPiIncomeReportingMedicalInsuranceList = response.data.acTaxPiIncomeReportingMedicalInsuranceList;
      this.open = true;
      this.title = \"商业健康保险明细编辑\";
    } else {
      console.error(\"response.data is empty\");
    }
  });
},

通过以上修改,代码会先判断row是否存在,若存在则使用row.chiId作为id,否则判断this.selection是否存在且长度大于0,若满足条件则使用this.selection[0].chiId作为id。同时,在获取数据后,会先判断response.data是否存在,若存在则继续处理数据,否则输出错误信息。


原文地址: https://www.cveoy.top/t/topic/pkoL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录