Tree: Fix issue #15538 caused by two Tree sharing the same data. (#15615)

* Tree: fix #15538 by adding more detect logic.

* Tree: fix #15538 and add test case.

* Tree: fix eslint error

* Tree: remove arrayContains function
This commit is contained in:
VanMess
2019-06-11 10:05:36 +08:00
committed by island205
parent 69715b6154
commit ca9a0330f8
2 changed files with 65 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import objectAssign from 'element-ui/src/utils/merge';
import { markNodeData, NODE_KEY } from './util';
import { arrayFindIndex } from 'element-ui/src/utils/util';
export const getChildState = node => {
let all = true;
@@ -435,8 +436,10 @@ export default class Node {
const newNodes = [];
newData.forEach((item, index) => {
if (item[NODE_KEY]) {
newDataMap[item[NODE_KEY]] = { index, data: item };
const key = item[NODE_KEY];
const isNodeExists = !!key && arrayFindIndex(oldData, data => data[NODE_KEY] === key) >= 0;
if (isNodeExists) {
newDataMap[key] = { index, data: item };
} else {
newNodes.push({ index, data: item });
}