解决bootstrap-treeview树形结构缩进异常

如题目所述,在使用该插件时发现缩进异常,找到一篇关于解决方案,发现多层结构还是有异常。

原文:解决bootstrap-treeview树形结构缩进异常_的博客-CSDN博客

源代码如下

 var g=function(child){
                var childLevel=that.options.treeRootLevel+levelStep;
                $.each(child, function (i, n) {
                    n.level=childLevel;
                    if (that.options.treeCollapseAll) {
                        n.hidden = true;
                    }
                    var subChild = getChild(n, that.data, that.options.treeId,that.options.treeParentId);
                    if(subChild==null || subChild.length==0){
                        n.isLeaf=true;
                    }
                    rows.push(n);
                    if(subChild!=null && subChild.length>0){
                        levelStep++;
                        g(subChild);
                    }else{
                        levelStep=1;
                    }
                });
            }

改造为

 var g = function (child) {
                var childLevel = that.options.treeRootLevel + levelStep;
                $.each(child, function (i, n) {
                    n.level = childLevel;
                    if (that.options.treeCollapseAll) {
                        n.hidden = true;
                    }
                    var subChild = getChild(n, that.data, that.options.treeId,that.options.treeParentId);
                    if(subChild==null || subChild.length==0){
                        n.isLeaf=true;
                    }
                    rows.push(n);
                    if (subChild != null && subChild.length > 0) {
                        levelStep++;
                        g(subChild);
                    } else {
                        //nio
                        if (i == (child.length - 1)) {
                            levelStep--;
                        }
                    }
                    if (childLevel > 1) {
                        levelStep = childLevel - 1;
                    }
                });
            }

至此暂未发现bug。

你可能感兴趣的:(bootstrap,javascript,前端)