el-select下拉框多选处理选中数据

在这里插入图片描述
el-select下拉框设置多选属性:multiple

<el-col :span="8">
   <el-form-item label="保管员"  label-width="120px">
      <el-select
        v-model="form.custodianList"
        :disabled="isDetail" 
        :placeholder="isDetail ? '' : '请选择保管员'"
        style="width: 100%"
        multiple  
        clearable
        @change="(value) => handleChange('custodianList', value)"
      >
        <el-option
          v-for="item in custodianList"
          :key="item.partyCode"
          :label="item.partyName"
          :value="item.partyCode"
        />
      </el-select>
    </el-form-item>
 </el-col>
** //处理保管员,保管员,装卸工多选
    handleChange(str, val) {
      let that = this
      let arr = []
      做出两种方法,逻辑都是一样的
      第一种是循环两次:代码如下
      // for (let i = 0; i < val.length; i++) {
      //   for (let j = 0; j < that.custodianList.length; j++) {
      //     if (val[i] === that.custodianList[j].code) {
      //       arr.push(that.custodianList[j])
      //     }
      //   }
      // }
	  //这里的一层if是因为三个下拉框调取的一个方法  用参数str区分不同的下拉框
      if (str === 'custodianList') { 
      第二种是使用一层for加一个Array.find方法
        for (let i in val) {
          that.custodianList.find((item) => {
            if (item.partyCode === val[i]) {
              arr.push(item)
            }
          })
        }
        that.form.custodianList = arr
      } 
    },**

版权声明:本文为chenThreeMetals原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。