项目中使用到了bootstrap-treeview,但是他的缩进存在异常,查看源码发现他的缩进有一个level属性来控制,level属性的变化由方法initData来控制。修改如下:
var g = function (child) {
var childLevel = 0;
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);
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太多,而且基本不处理。