From 677f4e2cd7c8a13d503fac485d0d2688ddfd429a Mon Sep 17 00:00:00 2001 From: Jsonz Date: Fri, 8 Apr 2022 10:46:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=20=E5=88=9B=E5=BB=BA=20treeStore?= =?UTF-8?q?=E6=97=B6=E4=BC=A0=E5=85=A5=20keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cascader/Cascader.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cascader/Cascader.tsx b/src/cascader/Cascader.tsx index 7374875f0..c0d06edde 100644 --- a/src/cascader/Cascader.tsx +++ b/src/cascader/Cascader.tsx @@ -93,15 +93,21 @@ const Cascader: React.FC = (props) => { /** * build tree */ - const { disabled, options = [], keys, checkStrictly = false, lazy = true, load, valueMode = 'onlyLeaf' } = props; + const { disabled, options = [], keys = {}, checkStrictly = false, lazy = true, load, valueMode = 'onlyLeaf' } = props; useEffect(() => { if (!options.length) return; if (!treeStore) { const createStore = (onLoad: () => void) => { + const treePropsKeys = { + ...keys, + children: typeof keys.children === 'string' ? keys.children : 'children', + }; + const treeProps = { onLoad, options, + keys: treePropsKeys, }; const store = new TreeStore(treeProps); store.append(options); @@ -119,7 +125,7 @@ const Cascader: React.FC = (props) => { treeStoreExpendEffect(treeStore, value, []); treeNodesEffect(inputVal, treeStore, setTreeNodes); } - }, [inputVal, options, value, treeStore]); + }, [inputVal, options, value, treeStore, keys]); useEffect(() => { if (!treeStore) return;