table 组件,树结构数据,当数据发生变更时,非根节点的选中状态会丢失
- Dominant language
- Vue
- Stars
- 54k
- Forks
- 14.4k
- PR merge metrics
- No merged PRs in 30d
Description
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used [patch-package](https://github.com/ds300/patch-package) to patch `element-ui@2.15.8` for the project I'm working on.
Here is the diff that solved my problem:
```diff
diff --git a/node_modules/element-ui/packages/table/src/store/watcher.js b/node_modules/element-ui/packages/table/src/store/watcher.js
index fa13bdc..822d8f1 100644
--- a/node_modules/element-ui/packages/table/src/store/watcher.js
+++ b/node_modules/element-ui/packages/table/src/store/watcher.js
@@ -1,6 +1,6 @@
import Vue from 'vue';
import merge from 'element-ui/src/utils/merge';
-import { getKeysMap, getRowIdentity, getColumnById, getColumnByKey, orderBy, toggleRowStatus } from '../util';
+import { getKeysMap, getRowIdentity, getColumnById, getColumnByKey, orderBy, toggleRowStatus, flatTree } from '../util';
import expand from './expand';
import current from './current';
import tree from './tree';
@@ -200,7 +200,8 @@ export default Vue.extend({
const states = this.states;
const { selection, rowKey, data } = states;
const selectedMap = getKeysMap(selection, rowKey);
- data.forEach(row => {
+ // fix: data未包含子节点,flatTree将树结构铺平
+ flatTree(data).forEach(row => {
const rowId = getRowIdentity(row, rowKey);
const rowInfo = selectedMap[rowId];
if (rowInfo) {
diff --git a/node_modules/element-ui/packages/table/src/util.js b/node_modules/element-ui/packages/table/src/util.js
index 7bbec8d..9af6149 100644
--- a/node_modules/element-ui/packages/table/src/util.js
+++ b/node_modules/element-ui/packages/table/src/util.js
@@ -253,3 +253,16 @@ export function walkTreeNode(root, cb, childrenKey = 'children', lazyKey = 'hasC
}
});
}
+
+export const flatTree = tree => {
+ let result = [];
+ const flat = nodes => {
+ if (nodes && nodes.length > 0)
+ nodes.forEach(node => {
+ result.push(node);
+ flat(node.children);
+ });
+ };
+ flat(tree);
+ return result
+}
This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.