修复 treeTable `reload` 和 `reloadData` 传参中带了 parseData 和 done 回调的时候渲染异常问题

pull/1247/head
sunxiaobin89 2023-04-28 18:10:44 +08:00
parent ab16f47dd1
commit 221009ee51
1 changed files with 45 additions and 28 deletions

View File

@ -111,31 +111,18 @@ layui.define(['table'], function (exports) {
}) })
} }
Class.prototype.init = function () { var updateOptions = function (id, options, reload) {
var that = this; var that = getThisTable(id);
var options = that.config; var thatOptionsTemp = $.extend(true, {} , that.getOptions(), options);
var treeOptions = thatOptionsTemp.tree;
// 先初始一个空的表格以便拿到对应的表格实例信息 var childrenKey = treeOptions.customName.children;
var tableIns = table.render($.extend({}, options, {
data: [],
url: '',
done: null
}))
var id = tableIns.config.id;
thisTreeTable.that[id] = that; // 记录当前实例对象
that.tableIns = tableIns;
var treeOptions = options.tree;
var customName = treeOptions.customName;
var isParentKey = customName.isParent;
var childrenKey = customName.children;
// 处理属性 // 处理属性
var parseData = options.parseData; var parseData = options.parseData;
var done = options.done; var done = options.done;
if (options.url) { if (thatOptionsTemp.url) {
// 异步加载的时候需要处理parseData进行转换 // 异步加载的时候需要处理parseData进行转换
if (!reload || (reload && parseData && !parseData.mod)) {
options.parseData = function () { options.parseData = function () {
var parseDataThat = this; var parseDataThat = this;
var args = arguments; var args = arguments;
@ -153,6 +140,8 @@ layui.define(['table'], function (exports) {
return retData; return retData;
} }
options.parseData.mod = true
}
} else { } else {
options.data = options.data || []; options.data = options.data || [];
// 处理 isSimpleData // 处理 isSimpleData
@ -165,6 +154,7 @@ layui.define(['table'], function (exports) {
that.initData(options.data); that.initData(options.data);
} }
if (!reload || (reload && done && !done.mod)) {
options.done = function () { options.done = function () {
var args = arguments; var args = arguments;
var doneThat = this; var doneThat = this;
@ -191,6 +181,30 @@ layui.define(['table'], function (exports) {
return done.apply(doneThat, args); return done.apply(doneThat, args);
} }
} }
options.done.mod = true;
}
}
Class.prototype.init = function () {
var that = this;
var options = that.config;
// 先初始一个空的表格以便拿到对应的表格实例信息
var tableIns = table.render($.extend({}, options, {
data: [],
url: '',
done: null
}))
var id = tableIns.config.id;
thisTreeTable.that[id] = that; // 记录当前实例对象
that.tableIns = tableIns;
// var treeOptions = options.tree;
// var customName = treeOptions.customName;
// var isParentKey = customName.isParent;
// var childrenKey = customName.children;
updateOptions(id, options);
} }
// 初始默认配置 // 初始默认配置
@ -819,6 +833,9 @@ layui.define(['table'], function (exports) {
if (layui.type(item) === 'array') delete that.config[key]; if (layui.type(item) === 'array') delete that.config[key];
}); });
// 根据需要处理options中的一些参数
updateOptions(that.config.id, options, true);
// 对参数进行深度或浅扩展 // 对参数进行深度或浅扩展
that.config = $.extend(deep, {}, that.config, options); that.config = $.extend(deep, {}, that.config, options);