var a=[ {   "id" : "0000", "text" : "R1", "children" : [ {   "id" : "8978", "text" : "Aad",    "children" : [ {   "id" : "2312", "text" : "adaada", "children" : [ {   "id" : "5154", "text" : "asdsa"   }] },{    "id" : "4544", "text" : "afasf",  "children" : [ {   "id" : "5236", "text" : "afasf"   }, {   "id" : "2328", "text" : "afasf"   } ]    }] }, {   "id" : "7867", "text" : "R2", "children" : [ {   "id" : "8767", "text" : "afasf",  "children" : [ {   "id" : "2016", "text" : "afafa"   }, {   "id" : "2017", "text" : "afasd"   } ]    }, {   "id" : "7657", "text" : "h",  "children" : [ {   "id" : "7867", "text" : "afras"   } ]    } ]    } ]    } ];
function buildArray(arrOrigin, id){
var arr = [] // 操作数组
,re =[] // 结果 AND 是否匹配到
,run = true // 运行 // arrOrigin 解析
arrOrigin.map(e=> {
arr.push({
id: e.parent_id,
children: [e],
nextFuncTag: true, // 下一个函数的起点标识
})
}) /**
* 组查询 (无状态函数)
* @e{Array} 下一个元素
*/
function select(e){
if(!run)return
// 截取段落
e.nextFuncTag && (re = [])
if(typeof(e.id)!="undefined")
{
re.push(e.id);
} if(e.id == id){
run = false
}else// 下一级查询
if(e.children && e.children.length != 0){
e.children.map(select)
}
} arr.map(select) return re
}
console.log(buildArray(a, 2312));//["0000", "8978", "2312"]

  

最新文章

  1. 深入理解DOM节点关系
  2. TFS修改项目名称
  3. Eclipse 使用maven创建Dynamic Web Project
  4. dll return a string
  5. js注入,黑客之路必备!
  6. Revit二次开发示例:HelloRevit
  7. gmail
  8. [转]关于 Swift 的一点初步看法
  9. OCA读书笔记(18) - 使用Support工具
  10. BFS,DFS伪代码
  11. regress
  12. Springboot 框架学习
  13. sql server 高可用镜像
  14. python基础学习小结
  15. PyMysql的LIKE查询%问题
  16. L1-037 A除以B (10 分)
  17. c语言01次作业--分支,顺序结构
  18. 20155324 2016-2017-2 《Java程序设计》第3周学习总结
  19. Office Web Apps 2013 修改Excel在线查看文件大小限制
  20. #10072. 「一本通 3.2 例 1」Sightseeing Trip(floyd求最小环+路径)

热门文章

  1. Debian9安装vim和vim无法右键鼠标粘贴解决方法
  2. 对Can We Make Operating Systems Reliable and Secure 的翻译
  3. celery 定时任务
  4. LeetCode算法题-Excel Sheet Column Number(Java实现)
  5. June 12. 2018 Week 24th. Tuesday
  6. Python里面search()和match()的区别
  7. 【Linux常见问题】Centos7的网络配置问题
  8. linux crontab定时器
  9. 在 Linux 中自动配置 IPv6 地址
  10. 小a的轰炸游戏 (差分)