going-client(三)zTree使用自定义字体图标

上一节写了ztree使用字体图标,因为当时时间比较晚,只能仓促都将字体图标写死,自然这样是不符合项目要求的,变更图标显示才有价值。
图标映射:左边为参数名字 右边为ztree的图标calss名字
openIcon------》root_open
closeIcon------》root_close
openFolder------》ico_open
closeFolder------》ico_close
openIcon------》bottom_open
closeIcon------》bottom_close
detailIcon------》icon-detail

第一步:修改replaceClassName方法,从参数中获取,如果不存在才取默认值

function replaceClassName(str,treeObj){
    console.log(str,"--1--ddd");
    var icons={};
    if(typeof treeObj!='undefined'){
        icons=treeObj["icons"];
    }

    str=str.replace("root_open","root_open "+(icons["openIcon"]||'icon-minus-square')+" icon goingicon");
    str=str.replace("root_close","root_close "+(icons["closeIcon"]||'icon-plus-square')+" icon goingicon");
    str=str.replace("ico_open","ico_open "+(icons["openFolder"]||'icon-folder-open')+" icon goingicon");
    str=str.replace("ico_close","ico_close "+(icons["closeFolder"]||'icon-folder')+" icon goingicon");
    str=str.replace("bottom_open","bottom_open "+(icons["openIcon"]||'icon-minus-square')+"  icon goingicon");
    str=str.replace("bottom_close","bottom_close "+(icons["closeIcon"]||'icon-plus-square')+" icon goingicon");
    console.log(str,"--2--ddd");
    return str;
}

第二步:修改makeNodeIcoClass方法:

makeNodeIcoClass: function (a, b) {
            if(a.icons==null){
                a.icons={};
            }
            var openFolder=a.icons["openFolder"]||"icon-folder-open";
            var closeFolder=a.icons["closeFolder"]||"icon-folder";
            var detailIcon=a.icons["detailIcon"]||"icon-detail";

            var c = ["ico"];
            if (!b.isAjaxing) {
                var d = e.nodeIsParent(a, b);
                c[0] = (b.iconSkin ? b.iconSkin + "_" : "") + c[0];
                d ? c.push(b.open ? f.folder.OPEN +" "+openFolder: f.folder.CLOSE+" "+closeFolder) : c.push(f.folder.DOCU+" "+detailIcon)
            }
            return f.className.BUTTON + " " + c.join("_")+" "+"icon goingicon"
        }

第三步:修改makeNodeLineClass方法:

makeNodeLineClass: function (a, b) {
            var c = [];
            a.view.showLine ? b.level == 0 && b.isFirstNode && b.isLastNode ? c.push(f.line.ROOT) : b.level == 0 && b.isFirstNode ? c.push(f.line.ROOTS) : b.isLastNode ? c.push(f.line.BOTTOM) : c.push(f.line.CENTER) : c.push(f.line.NOLINE);
            e.nodeIsParent(a, b) ? c.push(b.open ? f.folder.OPEN : f.folder.CLOSE) : c.push(f.folder.DOCU);
            return replaceClassName(i.makeNodeLineClassEx(b) + c.join("_"),a)
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值