详解layui中的树形关于取值传值问题

2020-05-24 21:39:12易采站长站整理

}
this.ParendCheck(_this.getChildByClassName(xtree_p, 'layui-xtree-checkbox')[0]);
}
}

//渲染之前按照选中的末级去改变父级选中状态
layuiXtree.prototype.ParentCheckboxChecked = function (e) {
var _this = this;
if (e.parentNode.parentNode.getAttribute('class') == 'layui-xtree-item') {
var _pe = _this.getChildByClassName(e.parentNode.parentNode, 'layui-xtree-checkbox')[0];
_pe.checked = true;
_this.ParentCheckboxChecked(_pe);
}
}

//获取全部选中的末级checkbox对象
layuiXtree.prototype.GetChecked = function () {
var _this = this;
var arr = new Array();
var arrIndex = 0;
var cks = _this.getByClassName('layui-xtree-checkbox');
for (var i = 0; i < cks.length; i++) {
if (cks[i].checked && cks[i].getAttribute('data-xend') == '1') {
arr[arrIndex] = cks[i];
arrIndex++;
}
}
return arr;
}

//获取全部的原始checkbox对象
layuiXtree.prototype.GetAllCheckBox = function () {
var _this = this;
var arr = new Array();
var arrIndex = 0;
var cks = _this.getByClassName('layui-xtree-checkbox');
for (var i = 0; i < cks.length; i++) {
arr[arrIndex] = cks[i];
arrIndex++;
}
return arr;
}

//根据值来获取其父级的checkbox原dom对象
layuiXtree.prototype.GetParent = function (a) {
var _this = this;
var cks = _this.getByClassName('layui-xtree-checkbox');
for (var i = 0; i < cks.length; i++) {
if (cks[i].value == a) {
if (cks[i].parentNode.parentNode.getAttribute('id') == _this._container.getAttribute('id')) return null;
return _this.getChildByClassName(cks[i].parentNode.parentNode, 'layui-xtree-checkbox')[0];
}
}
return null;
}
}
});
}

function strToJson(str) {
var json = (new Function("return " + str))();
return json;
}
</script>