有这样的数据结构{value:"230000",label:"黑龙江省",pk:"1001Z01000000000SGGS",children:Array(13)}children:{value:"230100",label:"哈尔滨市",pk:"1001Z01000000000SGGT",children:Array(14)}{value:"230200",label:"齐哈尔市",pk:"1001Z01000000000SGHD",children:Array(10)}{value:"230300",label:"鸡西市",pk:"1001Z01000000000SGHV",children:Array(4)}children:{value:"230301",label:"市辖区",pk:"1001Z01000000000SGHW",children:Array(6)}{value:"230321",label:"鸡东县",pk:"1001Z01000000000SGI3"}{value:"230381",label:"虎林市",pk:"1001Z01000000000SGI4"}{value:"230382",label:"密山市",pk:"1001Z01000000000SGI5"}我有一个value数组.例如[230000,230100,230321]最后我要最后对应的label黑龙江省哈尔滨市鸡东县我应该如何去设计这个算法,更小的复杂度?
2 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
letdata=[230000,230100,230321]letPArr=[]//所有省letpIndex=PArr.findIndex(item=>item.value===data[0])letCArr=PArr[pIndex].childrenletcIndex=CArr.findIndex(item=>item.value===data[1])...以此类推,找到所有对应的index,然后你应该会了
幕布斯7119047
TA贡献1794条经验 获得超8个赞
{value:"230000",label:"黑龙江省",pk:"1001Z01000000000SGGS",children:Array(13)}children:{value:"230100",label:"哈尔滨市",pk:"1001Z01000000000SGGT",children:Array(14)}{value:"230200",label:"齐哈尔市",pk:"1001Z01000000000SGHD",children:Array(10)}{value:"230300",label:"鸡西市",pk:"1001Z01000000000SGHV",children:Array(4)}其实,不能改下数据的结构吗?{230000:{value:"230000",label:"黑龙江省",pk:"1001Z01000000000SGGS",children:Object}children:{230100:{value:"230100",label:"哈尔滨市",pk:"1001Z01000000000SGGT",children:Object}230200:{value:"230200",label:"齐哈尔市",pk:"1001Z01000000000SGHD",children:Object}230300:{value:"230300",label:"鸡西市",pk:"1001Z01000000000SGHV",children:Object}}}找[230000,230100,230321],object[230000]['children'][230100]['children'][230321]
添加回答
举报
0/150
提交
取消