The method of cascading selectors to bind the parent id

1. Query the content of the cascade selector department interface

queryDeptTree() {

varuserId=this.$store.getters.accountId

enterpriseDeptTree({ 'user_id':userId }).then(response=> {

this.deptOptions=response.data.data

this . makeDeptMap ( this . deptOptions ) //Make the obtained department structure id into a map

})

}

2. Make a map

//Store recursively into deptMap

makeDeptMap(currentDept) {

var dept

if (currentDept.length===1) {

dept=currentDept[0]

this . deptMap [ dept . deptId + '' ] = dept . pid //pid is the parent node id

if (dept.childEnterpriseDeptList!==undefined&&dept.childEnterpriseDeptList.length>0) {

this.makeDeptMap(dept.childEnterpriseDeptList)

}

} else {

currentDept.forEach(curDept=> {

dept=curDept

this.deptMap[dept.deptId+''] =dept.pid

if (dept.childEnterpriseDeptList!==undefined&&dept.childEnterpriseDeptList.length>0) {

this.makeDeptMap(dept.childEnterpriseDeptList)

}

})

}

}

3. Find the parent id of the current id to make an id string:

this.findAncestorById(this.oldDeptId)

findAncestorById ( deptId ) {

this.contentDept.unshift(deptId)

varcurDeptId=this.deptMap[deptId]

while (curDeptId!==undefined&&curDeptId!==0) {

this.contentDept.unshift(curDeptId)

curDeptId=this.deptMap[curDeptId]

}

}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325119095&siteId=291194637