Newer
Older
Nanping_sponge_JXKH / src / utils / commom.js
@liyingjing liyingjing on 25 Oct 2023 1 KB 海绵绩效考个

//递归删除选中id
export  function deleteData(data, nodeCode) {            
    let  newData = data.filter(x => x.nodeCode !== nodeCode)            
    newData.forEach(x => x.children && (x.children = deleteData(x.children, nodeCode)))            
    return newData
}
//递归往childerenpihs中id
export function getId(list,parentNodeCode) {
    for (let i in list) {
        if(list[i].nodeCode==parentNodeCode){
        return [list[i]]
      }
      if(list[i].children){
        let node=getId(list[i].children,parentNodeCode);
        if(node!==undefined){
            return node;
           }
      }
    }    
}
// 递归id,替换嵌套数组对象里面的对象
export  function  editTreeData (treeData,newTreeNode){ 
    for (let i = 0, len = treeData.length; i < len; i++) { 
     
      if (treeData[i].nodeCode === newTreeNode.parentNodeCode) {
        if(treeData[i].children){
            editTreeData(treeData[i].children,newTreeNode)
          }   
        treeData[i] = newTreeNode;
      }
    }
    return treeData 
}
// function editTreeData(treeData,newTreeNode){
//     for( var key in treeData){
//       if( key.id===treeData.id){
//         aa[key]="1234"
//       }
//       if(typeof aa[key] == "object"){
//         abc(aa[key])
//       }
//     }
//     return aa
//   }