fix: 修复 picker 点选时无法区分 false 和 数字 0 的问题 (#9193)

This commit is contained in:
liaoxuezhi 2023-12-20 18:58:48 +08:00 committed by GitHub
parent b14c3ab7cb
commit 0dcfb1d637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 25 deletions

View File

@ -210,20 +210,28 @@ export const ListStore = iRendererStore
function updateSelected(selected: Array<any>, 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);
});
}

View File

@ -1528,19 +1528,28 @@ export const TableStore = iRendererStore
function updateSelected(selected: Array<any>, 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();