方法
const findIndex = (needList, pId, cId, couId) => {
let indexList: number[] = [];
indexList[0] = needList.findIndex((item) => item.id === pId);
indexList[1] = needList[indexList[0]].children.findIndex((item) => item.id === cId);
indexList[2] = needList[indexList[0]].children[indexList[1]].children.findIndex((item) => item.id === couId);
return indexList;
};
调用
let index = findIndex(data, provinceId, cityId, countryId)
// index 就是一个索引数组 例如[2,3,3]
data为省市区三级联动列表
然后是 省市区id
该代码定义了一个名为findIndex的方法,用于在省市区三级联动列表中找到指定省、市、区的索引位置。方法首先查找省份ID,接着在对应的省份子列表中找城市ID,最后在城市子列表中找区县ID。返回的是一个包含三个索引值的数组。
752

被折叠的 条评论
为什么被折叠?



