关于使用elementUI中select和el-checkbox-group的回显问题

网上看到很关于这个的问题回显,各式各样,没有绝句自己的问题,总重问题出在数据格式上

select和el-checkbox-group   el-checkbox 都是字符串数组格式:['12','13',....];

我写的格式是id是选中的id组成的回显数据格式;

如果不会转换请看代码:...选中返回的数据.split(",")  把字符串转换成数组逗号隔开

这是两个数组对象中找相同的对象数组

 let result = []
        for(let i = 0; i < _that.JZOptions.length; i++) { //两个数组对象中找到相同的单独创建数组
          let tempArr1 = _that.JZOptions[i]
          for(let j = 0; j < newData.length; j++) {
            let tempArr2 = newData[j]
            if(tempArr2.name === tempArr1.name){
              result.push(tempArr1)
              break;
            }
          }
        }

这是字符串转数组对象:

const newData = [...res.canUsedUnits.split(",")].map((item,index) => ({ name: item}))

字符串前后两端去除空格

.replace(/^\s*|\s*$/g,"") == ""

相关推荐

  1. Vue <el-checkbox-group>多选框问题

    2024-03-15 13:04:03       35 阅读
  2. el-select

    2024-03-15 13:04:03       41 阅读
  3. 解决elementUI使用checkbox无法选中问题

    2024-03-15 13:04:03       38 阅读
  4. elementUIel-select选择器赋值为空后无法选中

    2024-03-15 13:04:03       8 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-15 13:04:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-15 13:04:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-15 13:04:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-15 13:04:03       20 阅读

热门阅读

  1. Babel 7.24.0 出来了!

    2024-03-15 13:04:03       16 阅读
  2. go生成terraform .tf配置

    2024-03-15 13:04:03       22 阅读
  3. 程序员如何选择职业赛道?

    2024-03-15 13:04:03       22 阅读
  4. docker套娃实践(待续)

    2024-03-15 13:04:03       19 阅读
  5. Docker使用及部署流程

    2024-03-15 13:04:03       19 阅读
  6. C++for语句

    2024-03-15 13:04:03       20 阅读