From 3136e5964f3944fc5cd9aac1f97b1b1d1dc6936c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=99=A8=E6=88=90?= Date: Fri, 15 Nov 2019 15:05:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(tree):=20=E6=B7=BB=E5=8A=A0form-props-'rep?= =?UTF-8?q?laceFields'=E5=AD=97=E6=AE=B5=20(#1395)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(tree): 添加form-props-'replaceFields'字段 * test: add test file * docs: 修改实例名称 --- components/tree/Tree.jsx | 13 +++- .../__tests__/__snapshots__/demo.test.js.snap | 20 ++++++ components/tree/demo/index.vue | 2 + components/tree/demo/replaceFields.md | 67 +++++++++++++++++++ components/tree/index.en-US.md | 1 + components/tree/index.zh-CN.md | 1 + site/dev.js | 2 +- types/tree/tree.d.ts | 13 ++++ 8 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 components/tree/demo/replaceFields.md diff --git a/components/tree/Tree.jsx b/components/tree/Tree.jsx index 8fd7c7ceb..bf97528b7 100644 --- a/components/tree/Tree.jsx +++ b/components/tree/Tree.jsx @@ -87,6 +87,11 @@ function TreeProps() { openAnimation: PropTypes.any, treeNodes: PropTypes.array, treeData: PropTypes.array, + /** + * @default{title,key,children} + * 替换treeNode中 title,key,children字段为treeData中对应的字段 + */ + replaceFields: PropTypes.object, }; } @@ -151,13 +156,15 @@ export default { }, updateTreeData(treeData) { const { $slots, $scopedSlots } = this; + const defaultFields = { children: 'children', title: 'title', key: 'key' }; + const replaceFields = { ...defaultFields, ...this.$props.replaceFields }; return treeData.map(item => { + const key = item[replaceFields.key]; + const children = item[replaceFields.children]; const { - children, on = {}, slots = {}, scopedSlots = {}, - key, class: cls, style, ...restProps @@ -171,7 +178,7 @@ export default { title: $slots[slots.title] || ($scopedSlots[scopedSlots.title] && $scopedSlots[scopedSlots.title](item)) || - restProps.title, + restProps[replaceFields.title], dataRef: item, on, key, diff --git a/components/tree/__tests__/__snapshots__/demo.test.js.snap b/components/tree/__tests__/__snapshots__/demo.test.js.snap index 7e2b97f37..c92d5eeda 100644 --- a/components/tree/__tests__/__snapshots__/demo.test.js.snap +++ b/components/tree/__tests__/__snapshots__/demo.test.js.snap @@ -130,6 +130,26 @@ exports[`renders ./components/tree/demo/line.md correctly 1`] = ` `; +exports[`renders ./components/tree/demo/replaceFields.md correctly 1`] = ` + +`; + exports[`renders ./components/tree/demo/search.md correctly 1`] = `