ElementUI多选框组el-checkbox-group,重新勾选时不希望数组顺序被打乱

1、重新排序

let checkboxList=['a','b','c']
let checkList=['c','a']
let newCheckLIst=checkList.sort((a, b) => {
return checkboxList.indexOf(a) - checkboxList.indexOf(b)
})

  

2、如果是没法排序的汉字之类的,就只能用checkbox的数组进行filter,挨个去过滤是否在已选的数组中

let checkboxList=['a','b','c']
let checkList=['c','a']
const newCheckLIst = checkboxList.filter(item => checkList.includes(item))

 

转自:https://cloud.tencent.com/developer/article/1838270

posted @ 2022-04-25 13:52  贾平凡  阅读(750)  评论(0)    收藏  举报