注:
1、这里的layex.treeRender是封装好的,其他人要用的话,就正常按照layui的树写tree.render就行;
2、that.level:是vue中data声明的变量;
3、根节点的id=0;
let that = this;
layex.treeRender({
elem: '#goodsTree',
data: that.goods,
click: function(obj) {
/* 判断当前点击的树是几级--start */
let el = obj.elem[0].parentElement;
let level = el.childNodes[0].dataset.id;
let i = 0;
while(level != '0') {
el = el.parentElement;
level = el.childNodes[0].dataset.id;
++ i;
}
that.level = i/2;
/* 判断当前点击的树是几级--end */
}
})
我只想到了这个方法,希望能有更好的方法交流!