From 0dcfb1d6375154aa7fc4b2cfa11b6f88ef645957 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 20 Dec 2023 18:58:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20picker=20=E7=82=B9?= =?UTF-8?q?=E9=80=89=E6=97=B6=E6=97=A0=E6=B3=95=E5=8C=BA=E5=88=86=20false?= =?UTF-8?q?=20=E5=92=8C=20=E6=95=B0=E5=AD=97=200=20=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#9193)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/store/list.ts | 34 +++++++++++++++++---------- packages/amis-core/src/store/table.ts | 33 ++++++++++++++++---------- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/packages/amis-core/src/store/list.ts b/packages/amis-core/src/store/list.ts index a143e88d4..89dfba652 100644 --- a/packages/amis-core/src/store/list.ts +++ b/packages/amis-core/src/store/list.ts @@ -210,20 +210,28 @@ export const ListStore = iRendererStore function updateSelected(selected: Array, valueField?: string) { self.selectedItems.clear(); - self.items.forEach(item => { - if (~selected.indexOf(item.pristine)) { - self.selectedItems.push(item); - } else if ( - find(selected, a => { - const selectValue = a[valueField || 'value']; - const itemValue = item.pristine[valueField || 'value']; - return self.strictMode - ? selectValue === itemValue - : selectValue == itemValue; - }) - ) { - self.selectedItems.push(item); + selected.forEach(item => { + let resolved = self.items.find(a => a.pristine === item); + + // 先严格比较, + if (!resolved) { + resolved = self.items.find(a => { + const selectValue = item[valueField || 'value']; + const itemValue = a.pristine[valueField || 'value']; + return selectValue === itemValue; + }); } + + // 再宽松比较 + if (!resolved) { + resolved = self.items.find(a => { + const selectValue = item[valueField || 'value']; + const itemValue = a.pristine[valueField || 'value']; + return selectValue == itemValue; + }); + } + + resolved && self.selectedItems.push(resolved); }); } diff --git a/packages/amis-core/src/store/table.ts b/packages/amis-core/src/store/table.ts index 612c1bfbd..15dd5a946 100644 --- a/packages/amis-core/src/store/table.ts +++ b/packages/amis-core/src/store/table.ts @@ -1528,19 +1528,28 @@ export const TableStore = iRendererStore function updateSelected(selected: Array, valueField?: string) { self.selectedRows.clear(); - eachTree(self.rows, item => { - if (~selected.indexOf(item.pristine)) { - self.selectedRows.push(item.id); - } else if ( - find( - selected, - a => - a[valueField || 'value'] && - a[valueField || 'value'] == item.pristine[valueField || 'value'] - ) - ) { - self.selectedRows.push(item.id); + selected.forEach(item => { + let resolved = self.rows.find(a => a.pristine === item); + + // 先严格比较, + if (!resolved) { + resolved = self.rows.find(a => { + const selectValue = item[valueField || 'value']; + const itemValue = a.pristine[valueField || 'value']; + return selectValue === itemValue; + }); } + + // 再宽松比较 + if (!resolved) { + resolved = self.rows.find(a => { + const selectValue = item[valueField || 'value']; + const itemValue = a.pristine[valueField || 'value']; + return selectValue == itemValue; + }); + } + + resolved && self.selectedRows.push(resolved); }); updateCheckDisable();