js 广度优先遍历
Posted 偏灬爱
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 广度优先遍历相关的知识,希望对你有一定的参考价值。
; (function() { var def = function() { var me = this; me.data = { color_1: ‘#333333‘, color_2: ‘#1890ff‘, one: 1, txt: "node", arr: [{ click: false, txt: "parent-1", show: true, arr: [{ click: false, txt: "child-1", show: false, arr: [{ click: false, txt: "child-1-1", show: false }, { click: false, txt: "child-1-2", show: false }] }, { click: false, txt: "child-2", show: false }, { click: false, txt: "child-3", show: false }, { click: false, txt: "child-4", show: false }] }, { click: false, txt: "parent-2", show: true }, { click: false, txt: "parent-3", show: true }, { click: false, txt: "parent-4", show: true }] } me.key = "child-1-1" me.r = { count: 0,result:[] }; me.arr = []; me.start(me.r); console.log(me.r); }; def.prototype = { start: function(p) { var me = this; me.arr.push(me.data); while (me.arr.length) { p.count += 1; var tem = me.arr[0]; if (tem.arr) { tem.arr.forEach(i => { me.arr.push(i); }); } if (tem.txt === me.key) { me.r.result.push(tem); break; } me.r.result.push(me.arr.shift()); } } }; new def() })()
js 广度优先
以上是关于js 广度优先遍历的主要内容,如果未能解决你的问题,请参考以下文章