美文网首页
2018-10-31

2018-10-31

作者: 米诺zuo | 来源:发表于2018-10-31 15:28 被阅读2次
<script>
        function getArray(data,name){
            for (var i in data) {
                console.log('i',i);
                console.log('data'+i,data[i].children);
                if (data[i].name == name) {
                    console.log(data[i]);
                    break;
                } else {
                    getArray(data[i].children, name);
                }
            }
        }
        var data = [
           {
               name: '中国',
               children: [
                   {
                       name: '教第三节课',
                   },
                   {
                       name: '教呼呼',
                       children: [
                           {
                               name: '大一',
                               children: [
                                   {
                                       name: '课程1',
                                       children: [
                                           {
                                               name: '1231'
                                           },
                                           {
                                               name: '121'
                                           }
                                       ]
                                   },
                                   {
                                       name: '课程2',
                                       children: [
                                           {
                                               name: '1232'
                                           },
                                           {
                                               name: '122'
                                           }
                                       ]
                                   },
                                   {
                                       name: '课程3',
                                       children: [
                                           {
                                               name: '1233'
                                           },
                                           {
                                               name: '123'
                                           }
                                       ]
                                   },

                               ]
                           }
                       ]
                   },
                   {
                       name: '活动',
                       children:null
                   }
               ]
           }
       ];
        getArray(data,'活动');
        console.log(data);
        for(var i in undefined){
            alert(123);
        }
 
    </script>

原文链接:https://blog.csdn.net/yf275908654/article/details/52215321

相关文章

网友评论

      本文标题:2018-10-31

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