|
|
|
@ -95,7 +95,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
layui.each(data || tableCache, function (index, item) {
|
|
|
|
|
var itemDataIndex = item[LAY_DATA_INDEX] || '';
|
|
|
|
|
if (itemDataIndex.indexOf('-') !== -1) {
|
|
|
|
|
tableCache[itemDataIndex] = item
|
|
|
|
|
tableCache[itemDataIndex] = item;
|
|
|
|
|
}
|
|
|
|
|
item[childrenKey] && updateCache(id, childrenKey, item[childrenKey]);
|
|
|
|
|
})
|
|
|
|
@ -505,6 +505,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
var isParentKey = customName.isParent;
|
|
|
|
|
var childrenKey = customName.children;
|
|
|
|
|
|
|
|
|
|
var update = function(data, parentIndex){
|
|
|
|
|
layui.each(data, function (i1, item1) {
|
|
|
|
|
if (!(isParentKey in item1)) {
|
|
|
|
|
item1[isParentKey] = !!(item1[childrenKey] && item1[childrenKey].length);
|
|
|
|
@ -512,8 +513,11 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX];
|
|
|
|
|
item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || '';
|
|
|
|
|
var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1;
|
|
|
|
|
that.initData(item1[childrenKey] || [], dataIndex);
|
|
|
|
|
update(item1[childrenKey] || [], dataIndex);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update(data, parentIndex);
|
|
|
|
|
|
|
|
|
|
updateCache(tableId, childrenKey, data);
|
|
|
|
|
|
|
|
|
@ -1257,17 +1261,38 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
var tableView = options.elem.next();
|
|
|
|
|
var delNode;
|
|
|
|
|
var indexArr = [];
|
|
|
|
|
var tableCache = table.cache[id];
|
|
|
|
|
delNode = that.getNodeDataByIndex(layui.type(node) === 'string' ? node : node[LAY_DATA_INDEX], false, 'delete');
|
|
|
|
|
var nodeP = that.getNodeDataByIndex(delNode[LAY_PARENT_INDEX]);
|
|
|
|
|
that.updateCheckStatus(nodeP);
|
|
|
|
|
var delNodesFlat = that.treeToFlat([delNode], delNode[treeOptions.customName.pid], delNode[LAY_PARENT_INDEX]);
|
|
|
|
|
layui.each(delNodesFlat, function (i2, item2) {
|
|
|
|
|
indexArr.push('tr[lay-data-index="' + item2[LAY_DATA_INDEX] + '"]');
|
|
|
|
|
layui.each(delNodesFlat, function (i2, delNode) {
|
|
|
|
|
var delNodeDataIndex = delNode[LAY_DATA_INDEX];
|
|
|
|
|
indexArr.push('tr[lay-data-index="' + delNodeDataIndex + '"]');
|
|
|
|
|
// 删除临时 key
|
|
|
|
|
if(delNodeDataIndex.indexOf('-') !== -1){
|
|
|
|
|
delete tableCache[delNodeDataIndex];
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
tableView.find(indexArr.join(',')).remove(); // 删除行
|
|
|
|
|
|
|
|
|
|
var deleteCacheKey = function(){
|
|
|
|
|
for (var key in tableCache) {
|
|
|
|
|
// 根节点 getNodeDataByIndex 内部已处理
|
|
|
|
|
if(key.indexOf('-') !== -1){
|
|
|
|
|
// L93 updateCache() 中,cacheKey 取自 rowData 中的 LAY_DATA_INDEX,
|
|
|
|
|
// 两者不同说明当前 cacheKey 引用的 rowData 已被更新
|
|
|
|
|
if(key !== tableCache[key][LAY_DATA_INDEX]){
|
|
|
|
|
delete tableCache[key]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重新整理数据
|
|
|
|
|
var tableData = that.initData();
|
|
|
|
|
deleteCacheKey();
|
|
|
|
|
// index发生变化需要更新页面tr中对应的lay-data-index 新增和删除都要注意数据结构变动之后的index问题
|
|
|
|
|
layui.each(that.treeToFlat(tableData), function (i3, item3) {
|
|
|
|
|
if (item3[LAY_DATA_INDEX_HISTORY] && item3[LAY_DATA_INDEX_HISTORY] !== item3[LAY_DATA_INDEX]) {
|
|
|
|
@ -1279,7 +1304,7 @@ layui.define(['table'], function (exports) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 重新更新顶层节点的data-index;
|
|
|
|
|
layui.each(table.cache[id], function (i4, item4) {
|
|
|
|
|
layui.each(tableCache, function (i4, item4) {
|
|
|
|
|
tableView.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4);
|
|
|
|
|
})
|
|
|
|
|
options.hasNumberCol && formatNumber(that);
|
|
|
|
|