jquery tree循环渲染数据,控制checkbox显示与隐藏,点击无效效果

1.数据渲染

将数据渲染封装为对象函数:initShareListTreeData

initShareListTreeData:function(fileid) {    //share的树状图初始化
    var treedata = new Array();
    var oldSharedData = new Array();
    var crumb = $('#dir').val();
    OCchooses.notChecked_ID = [];
    $.ajax({
        type: 'POST',
        url: OC.filePath('core', 'ajax', 'getcheckboxdata.php'),
        data: {sharefileid: fileid, crumb:crumb},
        async: false,
        success: function(result) {
            if (result && result.status === 'success') {
                var count = 0;
                var arrayFlag = -1;
                oldSharedData = result.sharedto;
                //第一层
                $.each(result.data, function (n, value) {//机构
                    count++;
                    var jsondata = {};
                    jsondata.id = count;
                    jsondata.text = n;

                    if(n == t('core', 'Tempgroup') || n == t('core', 'Others')){
                        jsondata.attributes ={"flag": "none"};
                        OCchooses.notChecked_ID.push(count);//
                    }else{
                        jsondata.attributes ={"flag": "group"};

                        if(OCchooses.checkValueInArray(n, oldSharedData, 1)){
                            jsondata.checked = true;
                        }
                    }
                    jsondata.state = "closed";
                    if(0 != value.length){
                        //第二层,给机构下绑定处室
                        jsondata.children = new Array();
                        $.each(value, function (n_team, value_team) {//n_team:同一机构下所有处室
                            count++;
                            var userjsondata = {};
                            if(n == t('core', 'Tempgroup')) {

                                userjsondata.text = value_team;
                                userjsondata.attributes ={"flag" : "temp", "uid" : value_team};

                                if(OCchooses.checkValueInArray(value_team, oldSharedData, 1)){
                                    userjsondata.checked = true;
                                }
                                jsondata.children.push(userjsondata);
                            } else if(n == t('core', 'Others')) {
                                userjsondata.text = value_team['user'];
                                userjsondata.attributes ={"flag" : "temp", "uid" : value_team['user']};

                                if(OCchooses.checkValueInArray(value_team['user'], oldSharedData, 1)){
                                    userjsondata.checked = true;
                                }
                                jsondata.children.push(userjsondata);
                            } else {//groups start
                                var teamjsondata = {};
                                teamjsondata.id = count;
                                OCchooses.notChecked_ID.push(count);//cma
                                teamjsondata.text = n_team;
                                teamjsondata.attributes ={"flag": "team", "tid": n_team};
                                if(OCchooses.checkValueInArray(n_team, oldSharedData, 1)) {
                                    teamjsondata.checked = true;
                                }
                                jsondata.children.push(teamjsondata);
                                //第三层:给处室下绑定用户
                                if(0 != value_team.length) {
                                    teamjsondata.children = new Array();
                                    $.each(value_team, function (n_user, value_user) {//n_user:同一处室下所有用户
                                        count++;
                                        var userjsondata = {};
                                        userjsondata.id = count;
                                        if(value_user["user"]){
                                            userjsondata.text = value_user["user"];
                                            userjsondata.attributes ={"flag" : "user","uid" : value_user["user"]};

                                            if(OCchooses.checkValueInArray(value_user["user"], oldSharedData, 0)){
                                                userjsondata.checked = true;
                                            }
                                            teamjsondata.children.push(userjsondata);
                                        }else{
                                            userjsondata.text = value_user;
                                            userjsondata.attributes ={"flag" : "temp", "uid" : value_user};

                                            if(OCchooses.checkValueInArray(value_user, oldSharedData, 1)){
                                                userjsondata.checked = true;
                                            }
                                            jsondata.children.push(userjsondata);
                                        }
                                    });
                                }
                            }//groups end
                        });
                    }
                    treedata.push(jsondata);
                });
            } else {
                OC.dialogs.alert(t('core', 'Error while getting initdata'), t('core', 'Error'), '', true);
            }
        }
    });
    return [treedata,oldSharedData];
},

调用方式:

OCchooses.initdataShareList = OCchooses.initShareListTreeData(itemSource);//初始化树状图数据


2.控制显示或者隐藏checkbox按钮

将需要隐藏的按钮放在notChecked_ID中,循环后实现隐藏效果。

notCheckedbox:function(){
    $.each(OCchooses.notChecked_ID, function(i, notcheckid){
        var node = $('#treeall').tree('find', notcheckid);
        var dom = '#' + node.domId + " .tree-checkbox";
        $(dom).remove();
    });
},

调用:将teamjsondata.id直接push到notChecked_ID中就可以了。

teamjsondata.id = count;
OCchooses.notChecked_ID.push(count);//cma


3.若checkbox显示状态,控制点击事件,让其不生效

将需要控制点击不生效的按钮放在unClickCheck_ID中,循环后实现点击失效效果。

unclickCheck:function(){
    $.each(OCchooses.unClickCheck_ID, function(i, unclickcheckid){
        var node = $('#treeall').tree('find', unclickcheckid);
        var dom = '#' + node.domId + " .tree-checkbox";
        $(dom).unbind().click(function(){
            return false;
        });
    });
},

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值