@@ -195,22 +195,24 @@ export default {
195195 });
196196 },
197197 syncActivePath () {
198- let { checkedValue, store, multiple } = this ;
199- if (isEmpty (checkedValue)) {
198+ const { store , multiple , activePath , checkedValue } = this ;
199+
200+ if (! isEmpty (activePath)) {
201+ const nodes = activePath .map (node => this .getNodeByValue (node .getValue ()));
202+ this .expandNodes (nodes);
203+ } else if (! isEmpty (checkedValue)) {
204+ const value = multiple ? checkedValue[0 ] : checkedValue;
205+ const checkedNode = this .getNodeByValue (value) || {};
206+ const nodes = (checkedNode .pathNodes || []).slice (0 , - 1 );
207+ this .expandNodes (nodes);
208+ } else {
200209 this .activePath = [];
201210 this .menus = [store .getNodes ()];
202- } else {
203- checkedValue = multiple ? checkedValue[0 ] : checkedValue;
204- const checkedNode = this .getNodeByValue (checkedValue) || {};
205- const nodes = [];
206- let { parent } = checkedNode;
207- while (parent) {
208- nodes .unshift (parent);
209- parent = parent .parent ;
210- }
211- nodes .forEach (node => this .handleExpand (node, true /* silent */ ));
212211 }
213212 },
213+ expandNodes (nodes ) {
214+ nodes .forEach (node => this .handleExpand (node, true /* silent */ ));
215+ },
214216 calculateCheckedNodePaths () {
215217 const { checkedValue , multiple } = this ;
216218 const checkedValues = multiple
@@ -259,24 +261,26 @@ export default {
259261 }
260262 },
261263 handleExpand (node , silent ) {
264+ const { activePath } = this ;
262265 const { level } = node;
263- const path = this . activePath .slice (0 , level - 1 );
266+ const path = activePath .slice (0 , level - 1 );
264267 const menus = this .menus .slice (0 , level);
265268
266269 if (! node .isLeaf ) {
267270 path .push (node);
268271 menus .push (node .children );
269272 }
270273
271- if (valueEquals (path, this .activePath )) return ;
272-
273274 this .activePath = path;
274275 this .menus = menus;
275276
276277 if (! silent) {
277278 const pathValues = path .map (node => node .getValue ());
278- this .$emit (' active-item-change' , pathValues); // Deprecated
279- this .$emit (' expand-change' , pathValues);
279+ const activePathValues = activePath .map (node => node .getValue ());
280+ if (! valueEquals (pathValues, activePathValues)) {
281+ this .$emit (' active-item-change' , pathValues); // Deprecated
282+ this .$emit (' expand-change' , pathValues);
283+ }
280284 }
281285 },
282286 handleCheckChange (value ) {
@@ -321,6 +325,7 @@ export default {
321325 };
322326 config .lazyLoad (node, resolve);
323327 },
328+
324329 /**
325330 * public methods
326331 */
0 commit comments