mirror of https://github.com/layui/layui
fix(treetable): 修复 treeTable 由 #1808,#1792 导致的一些问题 (#1828)
* fix(treeTable): 重载时格式化图标异常 * fix(treeTable): 异步加载时, 加载图标异常 * fix(treeTable): 异步加载节点异常 related: #1792pull/1845/head
parent
fdbca99476
commit
54e35f2204
|
@ -213,10 +213,14 @@ layui.define(['table'], function (exports) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理图标
|
// 处理图标
|
||||||
|
if(options && options.tree && options.tree.view){
|
||||||
layui.each(ICON_PROPS, function(i, iconProp){
|
layui.each(ICON_PROPS, function(i, iconProp){
|
||||||
|
if(options.tree.view[iconProp] !== undefined){
|
||||||
options.tree.view[iconProp] = that.normalizedIcon(options.tree.view[iconProp]);
|
options.tree.view[iconProp] = that.normalizedIcon(options.tree.view[iconProp]);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Class.prototype.init = function () {
|
Class.prototype.init = function () {
|
||||||
var that = this;
|
var that = this;
|
||||||
|
@ -527,7 +531,9 @@ layui.define(['table'], function (exports) {
|
||||||
|
|
||||||
var update = function(data, parentIndex){
|
var update = function(data, parentIndex){
|
||||||
layui.each(data, function (i1, item1) {
|
layui.each(data, function (i1, item1) {
|
||||||
|
if (!(isParentKey in item1)) {
|
||||||
item1[isParentKey] = !!(item1[childrenKey] && item1[childrenKey].length);
|
item1[isParentKey] = !!(item1[childrenKey] && item1[childrenKey].length);
|
||||||
|
}
|
||||||
item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX];
|
item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX];
|
||||||
item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || '';
|
item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || '';
|
||||||
var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1;
|
var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1;
|
||||||
|
@ -587,6 +593,7 @@ layui.define(['table'], function (exports) {
|
||||||
|
|
||||||
// 找到表格中的同类节点(需要找到lay-data-index一致的所有行)
|
// 找到表格中的同类节点(需要找到lay-data-index一致的所有行)
|
||||||
var trsElem = tableViewElem.find('tr[lay-data-index="' + dataIndex + '"]');
|
var trsElem = tableViewElem.find('tr[lay-data-index="' + dataIndex + '"]');
|
||||||
|
var flexIconElem = trsElem.find('.layui-table-tree-flexIcon');
|
||||||
treeTableThat.updateNodeIcon({
|
treeTableThat.updateNodeIcon({
|
||||||
scopeEl: trsElem,
|
scopeEl: trsElem,
|
||||||
isExpand: trExpand,
|
isExpand: trExpand,
|
||||||
|
@ -1310,6 +1317,8 @@ layui.define(['table'], function (exports) {
|
||||||
|
|
||||||
var options = that.getOptions();
|
var options = that.getOptions();
|
||||||
var treeOptions = options.tree;
|
var treeOptions = options.tree;
|
||||||
|
var isParentKey = treeOptions.customName.isParent;
|
||||||
|
var childrenKey = treeOptions.customName.children;
|
||||||
var tableView = options.elem.next();
|
var tableView = options.elem.next();
|
||||||
var delNode;
|
var delNode;
|
||||||
var indexArr = [];
|
var indexArr = [];
|
||||||
|
@ -1360,13 +1369,14 @@ layui.define(['table'], function (exports) {
|
||||||
tableView.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4);
|
tableView.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4);
|
||||||
})
|
})
|
||||||
options.hasNumberCol && formatNumber(that);
|
options.hasNumberCol && formatNumber(that);
|
||||||
// 更新父节点图标状态
|
// 更新父节点状态
|
||||||
if(nodeP){
|
if(nodeP){
|
||||||
var trEl = tableView.find('tr[lay-data-index="' + nodeP[LAY_DATA_INDEX] + '"]');
|
var trEl = tableView.find('tr[lay-data-index="' + nodeP[LAY_DATA_INDEX] + '"]');
|
||||||
|
nodeP[isParentKey] = !!(nodeP[childrenKey] && nodeP[childrenKey].length);
|
||||||
that.updateNodeIcon({
|
that.updateNodeIcon({
|
||||||
scopeEl: trEl,
|
scopeEl: trEl,
|
||||||
isExpand: nodeP[LAY_EXPAND],
|
isExpand: nodeP[LAY_EXPAND],
|
||||||
isParent: nodeP[treeOptions.customName.isParent],
|
isParent: nodeP[isParentKey],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue