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

浙公网安备 33010602011771号