码迷,mamicode.com
首页 > 其他好文 > 详细

递归选中easyui树

时间:2019-07-04 17:47:47      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:cti   style   easyui   col   length   box   data   ==   mat   

 $(function(){
        // var data1 = [
        //     {
        //         "id": 3,
        //         "text": "3组织",
        //         "state": "open",
        //         "children": [
        //             { "id": 4,"text": "4岗位"},
        //             {"id": 5,"text": "5岗位", 
        //                 "children":[
        //                     {
        //                         "text":"6岗位",
        //                         "id":‘_6‘
        //                     },{
        //                         "id": ‘_7‘,
        //                         "text":"7岗位"
        //                     }
        //                 ]
        //             },
        //             {"id": ‘_8‘,"text": "8岗位"}
        //         ]
        //     },
        //     {"id": 9,"text": "9岗位"}
        // ];
        
        

        // function isChecked(data,arr){
        //     for(var i=0;i<arr.length;i++){
        //         for(var k = 0;k<data.length;k++){
        //             if(data[k].children==null || data[k].children.length<=0 ){
        //                 console.log( data[k].text );
        //                 if( data[k].id == arr[i] ){
        //                     data[k]["checked"]=true;
        //                 }
        //             }else{
        //                 if( data[k].id == arr[i] ){
        //                     data[k]["checked"]=true;
        //                 }else{
        //                     isChecked( data[k].children,[arr[i]] );
        //                 }
        //             }

        //         }
        //     }
        // }
        
        // var data1 = [
        //     {"id": 9,"text": "9岗位"},
        //     {
        //         "id": 3,
        //         "text": "3组织",
        //         "state": "open",
        //         "children": [
        //             { "id": ‘_4‘,"text": "4岗位"},
        //         ]
        //     }
        // ];
        // var arrId = [‘4‘,6,7,8];
        // function isChecked(data,arr){
        //     for(var i=0;i<arr.length;i++){
        //         for(var k = 0;k<data.length;k++){

        //             if( (data[k].id+‘‘).includes("_")  ){
        //                 console.log( "走含有_的路径" );
        //                 if(data[k].children==null || data[k].children.length<=0 ){
        //                     // console.log( data[k].text );
        //                     if( data[k].id.split("_")[1] == arr[i] ){
        //                         data[k]["checked"]=true;
        //                     }
        //                 }else{
        //                     if( data[k].id.split("_")[1] == arr[i] ){
        //                         data[k]["checked"]=true;
        //                     }else{
        //                         isChecked( data[k].children,[arr[i]] );
        //                     }
        //                 }
        //             }else if( !(data[k].id+‘‘).includes("_")){
        //                 console.log( "no!!!走不含有_的路径" );
        //                 if(data[k].children==null || data[k].children.length<=0 ){
        //                     // console.log( data[k].text );
        //                     if( data[k].id == arr[i] ){
        //                         data[k]["checked"]=true;
        //                     }
        //                 }else{
        //                     if( data[k].id == arr[i] ){
        //                         data[k]["checked"]=true;
        //                     }else{
        //                         isChecked( data[k].children,[arr[i]] );
        //                     }
        //                 }
        //             }

                    

        //         }
        //     }
        // }

        
        // isChecked(data1,arrId);
        // $("#dimensionTree").tree({
        //     data: data1,
        //     checkbox:true,
        //     animate:true
        // });

        //渲染树之前搞递归选中
        /*
        var data = [
            {"id": 9,"text": "9岗位"},
            {
                "id": 3,
                "text": "3组织",
                "state": "open",
                "children": [
                    { "id": 4,"text": "4岗位"},
                ]
            }
        ];
        isChecked(data);
        $("#dimensionTree").tree({
            data: data,
            checkbox:true,
            animate:true
        });
        function isChecked(data){
            var myId = 4; //此处需要循环id
            for(var k = 0;k<data.length;k++){
                if(data[k].children==null || data[k].children.length<=0 ){
                    console.log( data[k].text );
                    if( data[k].id == myId ){data[k]["checked"]=true;}
                }else{
                    if( data[k].id == myId ){data[k]["checked"]=true;}else{
                        isChecked( data[k].children );
                    }
                }

            }
        }

        */
    })
    

 

递归选中easyui树

标签:cti   style   easyui   col   length   box   data   ==   mat   

原文地址:https://www.cnblogs.com/smile-fanyin/p/11133412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!