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] =?UTF-8?q?table:=20[=E6=96=B0=E5=A2=9E]=20obj.updata()=20?= =?UTF-8?q?=E7=AC=AC=202=20=E4=B8=AA=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=9B=B4=E6=96=B0=E5=85=B6=E4=BB=96=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A8=A1=E6=9D=BF=E5=B9=B6=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E5=AD=98=E5=9C=A8=E5=85=B3=E8=81=94=E7=9A=84=E5=88=97?= =?UTF-8?q?=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);