element-ui使用动态渲染下拉选择框el-select已经选择的下拉框的值不可以重复选择让其disabled

调接口拿到下拉框数据的数据的时候将其disabled全为true

但是如果编辑的时候就需要与详情接口对比,如果有id一致就将disabled为true

复制代码
if (res.code == 0) {
           if (this.dialogtitle == "新增合同") {
              res.data.map((v) => {
                v.nameUnitVoList.forEach((item) => {
                  item.disabled = false;
                });
              });
            } else {
              this.tabsOptions.map((v) => {
                v.editableTabs.map((t) => {
                  t.tableProductData.map((n) => {
                    res.data.map((m) => {
                      m.nameUnitVoList.forEach((item) => {
                        if(item.enterpriseProduceId == n.enterpriseProduceId)
                        item.disabled = true;
                      });
                    });
                  });
                });
              });
            }
       }

在下拉框的change事件与删除事件中抽离一个方法

1.如果是flag是del且有name,说明这一行被删除,将当前的name在this.types去掉

否则就是下拉框change,然后将name追加到this.types

2.如果是编辑有的值已经被选择了此时前面接口已处理disabled为true,所以判断如果disabled为true也将name追加到this.types

3.下拉框change改变值的时候,拿到change改变值的之前的值,将其name从this.types筛选掉

4.再将下拉框下拉数据与this.types比较,如果里面name能找到就将其下拉数据disabled 置为true

复制代码
    nameChange(e, row) {
      this.getChoiceArr(row);
     }
    del(index, row) {
      this.getChoiceArr(row,'del')
      this.tableProductData.splice(index, 1);
      this.$emit("sentdelTableInfo", {});
    }, 
    //抽离一个方法
   getChoiceArr(row,flag) {
      this.types = []
      //preValue === 拿到产品名称下拉框变更之前的值
      const preValue = this.$refs[row.enterpriseProduceId].value
      if (flag == 'del' &&  row.name) {
        //如果是删除就让当前的name在this.types去掉
        this.types = this.types.filter(v=>(v != row.name))
      }else{
        this.types.push(row.name);
      }
      row.options.optionProSize.forEach((t) => {
        //编辑的时候需要将之前选择的disabled是true也要追加进去this.types
        if(t.disabled){
          this.types.push(t.name);
        }
        //console.log(this.types, "types");//|| t.disabled
        //当我们变更值的时候需要将上一个值变成可选的值,筛选掉
        this.types = this.types.filter(v=>(v != preValue))
        if (this.types.indexOf(t.name) !== -1) {
          t.disabled = true;
        } else {
          t.disabled = false;
        }
      });
    },  
相关推荐
xiaoye-duck7 小时前
【C++:异常】C++ 异常讲解指南:从理论到实践,深入理解栈展开和优雅处理程序错误
开发语言·c++·异常
qq_452396237 小时前
【工程实战】第八篇:报告美学 —— Allure 深度定制:让 Bug 定位精准到秒
开发语言·python·bug
px不是xp7 小时前
DeepSeek API集成:让小程序拥有AI大脑
javascript·人工智能·小程序
Zqrnja7 小时前
PTA 2026天体选拔赛(多校联赛)L2-1 仪式网络(C++ 含代码解释)
开发语言·c++
llm大模型算法工程师weng8 小时前
负载均衡做什么?nginx是什么
运维·开发语言·nginx·负载均衡
逆境不可逃8 小时前
【后端新手谈13】VO、BO、PO、DO、DTO:Java 分层开发的 5 大核心数据对象
java·开发语言
古月方枘Fry8 小时前
三层交换+VRRP实现负载
开发语言·网络·php
qq_5470261798 小时前
Java 中的 Caffeine 缓存详解
java·开发语言·缓存
froginwe118 小时前
JSP 发送邮件
开发语言
沐雪轻挽萤8 小时前
15. C++17新特性-std::string_view
java·开发语言·c++