From 3484a69c726336617a34123da7411eddf6860c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Thu, 7 Jul 2022 12:34:01 +0800 Subject: [PATCH 1/4] fix a minor error --- src/modules/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/table.js b/src/modules/table.js index 97acb8ad..ece1aaa5 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1773,7 +1773,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ tr.remove(); that.scrollPatch(); } - ,update: function(fields, ){ //修改行数据 + ,update: function(fields){ //修改行数据 fields = fields || {}; layui.each(fields, function(key, value){ var td = tr.children('td[data-field="'+ key +'"]'); From 831a2af0c909cd8ba6d8e29a532681b37a10c321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:56:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?table:=20[=E6=96=B0=E5=A2=9E]=20obj.updata(?= =?UTF-8?q?)=20=E7=AC=AC=202=20=E4=B8=AA=E5=8F=82=E6=95=B0=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=9B=B4=E6=96=B0=E5=85=B6=E4=BB=96=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E6=9D=BF=E5=B9=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=AD=98=E5=9C=A8=E5=85=B3=E8=81=94=E7=9A=84?= =?UTF-8?q?=E5=88=97=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/table.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/modules/table.js b/src/modules/table.js index ece1aaa5..cf121321 100644 --- a/src/modules/table.js +++ b/src/modules/table.js @@ -1773,7 +1773,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ tr.remove(); that.scrollPatch(); } - ,update: function(fields){ //修改行数据 + ,update: function(fields, related){ //修改行数据 fields = fields || {}; layui.each(fields, function(key, value){ var td = tr.children('td[data-field="'+ key +'"]'); @@ -1782,8 +1782,7 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ // 更新缓存中的数据 if(key in data) data[key] = value; - // 更新相应列视 - // 若要更新其它列与之有关的动态模板,直接采用 reloadData 方法 + // 更新相应列视图 that.eachCols(function(i, item3){ if(item3.field == key){ cell.html(parseTempData.call(that, { @@ -1792,9 +1791,22 @@ layui.define(['laytpl', 'laypage', 'form', 'util'], function(exports){ ,tplData: data })); td.data('content', value); + } + // 更新其他包含自定义模板且可能有所关联的列视图 + else if(related && (item3.templet || item3.toolbar)){ + var thisTd = tr.children('td[data-field="'+ (item3.field || i) +'"]'); + var content = data[item3.field]; + + thisTd.children(ELEM_CELL).html(parseTempData.call(that, { + item3: item3 + ,content: content + ,tplData: data + })); + thisTd.data('content', content); } }); }); + that.renderForm(); } }, sets); From 90d1542205112454f401c8f55fdd259eaf21178c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sat, 9 Jul 2022 19:04:49 +0800 Subject: [PATCH 3/4] optimizing code --- examples/form.html | 6 ++--- src/modules/form.js | 62 ++++++++++++++++++--------------------------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/examples/form.html b/examples/form.html index e82fae3b..a728226d 100644 --- a/examples/form.html +++ b/examples/form.html @@ -16,7 +16,6 @@
-