Skip to content

Commit 351528b

Browse files
committed
fix(tree-select): 删除父节点的最后一个子节点后选中了另外的子节点. vueComponent#3508
1 parent e179ded commit 351528b

File tree

1 file changed

+9
-1
lines changed
  • components/vc-tree-select/src

1 file changed

+9
-1
lines changed

components/vc-tree-select/src/util.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,22 @@ export function parseSimpleTreeData(treeData, { id, pId, rootPId }) {
162162
/**
163163
* Detect if position has relation.
164164
* e.g. 1-2 related with 1-2-3
165+
* e.g. 1-2-3 related with 1-2-4
165166
* e.g. 1-3-2 related with 1
166167
* e.g. 1-2 not related with 1-21
167168
*/
168169
export function isPosRelated(pos1, pos2) {
169170
const fields1 = pos1.split('-');
170171
const fields2 = pos2.split('-');
171172

172-
const minLen = Math.min(fields1.length, fields2.length);
173+
let minLen;
174+
if (fields1.length === fields2.length) {
175+
// e.g. 1-2-3 related with 1-2-4
176+
minLen = Math.max(fields1.length - 1, 0);
177+
} else {
178+
minLen = Math.min(fields1.length, fields2.length);
179+
}
180+
173181
for (let i = 0; i < minLen; i += 1) {
174182
if (fields1[i] !== fields2[i]) {
175183
return false;

0 commit comments

Comments
 (0)