美文网首页JS
树形数组查找目标对象

树形数组查找目标对象

作者: 你好岁月神偷 | 来源:发表于2021-08-31 22:04 被阅读0次

breadthQuery(tree, id) {

       var stark = [];

       stark = stark.concat(tree);

        while(stark.length) {

            var temp = stark.shift();

            if(temp.children) {

                stark = stark.concat(temp.children);

             }

             if(temp.cpiId === id) {

                return temp;

              }

         }

   }

tree: 数据源   目标属性:  id

相关文章

网友评论

    本文标题:树形数组查找目标对象

    本文链接:https://www.haomeiwen.com/subject/judtwltx.html