递归选中easyui树

 $(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 );
                    }
                }

            }
        }

        */
    })
    

 

转载于:https://www.cnblogs.com/smile-fanyin/p/11133412.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值