From a5911445a66227a05ff546574f9427085ce57347 Mon Sep 17 00:00:00 2001 From: Vi Pro Date: Thu, 8 Mar 2018 01:36:12 +0800 Subject: [PATCH] fix(MdTable): emit selected/update event only when selected items really changed (#1585) * fix(MdTable): only emit selected / update event when selected item(s) really changed fix #1559 * refactor(MdTable): selectedItems check changed beautify --- src/components/MdTable/MdTable.vue | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/MdTable/MdTable.vue b/src/components/MdTable/MdTable.vue index 6046165eb..0b27f5baf 100644 --- a/src/components/MdTable/MdTable.vue +++ b/src/components/MdTable/MdTable.vue @@ -222,11 +222,28 @@ this.MdTable.hasValue = this.hasValue } }, - 'MdTable.selectedItems' (val) { - this.select(val) + 'MdTable.selectedItems' (val, old) { + let changed = (() => { + let isValEmpty = !val || val.length === 0 + let isOldEmpty = !old || old.length === 0 + + if (isValEmpty && isOldEmpty) { + return false + } else if (!isValEmpty && !isOldEmpty) { + return (val.length !== old.length) ? true : !val.every((item, index) => item == old[index]) + } else { + return true + } + })() + + if (changed) { + this.select(val) + } }, - 'MdTable.singleSelection' (val) { - this.select(val) + 'MdTable.singleSelection' (val, old) { + if (val != old) { + this.select(val) + } }, mdSelectedValue () { this.syncSelectedValue()