mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-06 12:17:13 +08:00
fix(tree): filter prop does not work when assgined childrenFiled (#1479)
Co-authored-by: unknown <liyang@xiaoyouzi.com>
This commit is contained in:
parent
f1fd51e0ed
commit
66548d127f
@ -5,6 +5,7 @@
|
|||||||
## Fixes
|
## Fixes
|
||||||
|
|
||||||
- Fix `n-tabs` switch tab does not work when adding a new tab, closes [#1417](https://github.com/TuSimple/naive-ui/issues/1417).
|
- Fix `n-tabs` switch tab does not work when adding a new tab, closes [#1417](https://github.com/TuSimple/naive-ui/issues/1417).
|
||||||
|
- Fix `n-tree`'s `filter` prop does not work when assigned `children-field` , closes [#1477](https://github.com/TuSimple/naive-ui/issues/1477).
|
||||||
|
|
||||||
## 2.20.0 (2021-10-28)
|
## 2.20.0 (2021-10-28)
|
||||||
|
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
|
|
||||||
## Fixes
|
## Fixes
|
||||||
|
|
||||||
- 修复 `n-tabs` 在新增 tab 后切换 tab 无法生效,关闭 [#1417]https://github.com/TuSimple/naive-ui/issues/1417)
|
- 修复 `n-tabs` 在新增 tab 后切换 tab 无法生效,关闭 [#1417](https://github.com/TuSimple/naive-ui/issues/1417)
|
||||||
|
- 修复 `n-tree` 当指定`children-field`时过滤不生效,关闭 [#1477](https://github.com/TuSimple/naive-ui/issues/1477)
|
||||||
|
|
||||||
## 2.20.0 (2021-10-28)
|
## 2.20.0 (2021-10-28)
|
||||||
|
|
||||||
|
@ -374,6 +374,7 @@ export default defineComponent({
|
|||||||
props.data,
|
props.data,
|
||||||
props.pattern,
|
props.pattern,
|
||||||
props.keyField,
|
props.keyField,
|
||||||
|
props.childrenField,
|
||||||
mergedFilterRef.value
|
mergedFilterRef.value
|
||||||
)
|
)
|
||||||
uncontrolledHighlightKeySetRef.value = highlightKeySet
|
uncontrolledHighlightKeySetRef.value = highlightKeySet
|
||||||
|
@ -2,12 +2,18 @@ import { Key, TreeOption } from './interface'
|
|||||||
|
|
||||||
function traverse (
|
function traverse (
|
||||||
nodes: TreeOption[] | undefined,
|
nodes: TreeOption[] | undefined,
|
||||||
|
childrenField: string,
|
||||||
callback: (node: TreeOption) => void,
|
callback: (node: TreeOption) => void,
|
||||||
callbackAfter: (node: TreeOption) => void
|
callbackAfter: (node: TreeOption) => void
|
||||||
): void {
|
): void {
|
||||||
nodes?.forEach((node) => {
|
nodes?.forEach((node) => {
|
||||||
callback(node)
|
callback(node)
|
||||||
traverse(node.children, callback, callbackAfter)
|
traverse(
|
||||||
|
(node as any)[childrenField],
|
||||||
|
childrenField,
|
||||||
|
callback,
|
||||||
|
callbackAfter
|
||||||
|
)
|
||||||
callbackAfter(node)
|
callbackAfter(node)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -16,6 +22,7 @@ export function keysWithFilter (
|
|||||||
nodes: TreeOption[],
|
nodes: TreeOption[],
|
||||||
pattern: string,
|
pattern: string,
|
||||||
keyField: string,
|
keyField: string,
|
||||||
|
childrenField: string,
|
||||||
filter: (pattern: string, node: TreeOption) => boolean
|
filter: (pattern: string, node: TreeOption) => boolean
|
||||||
): {
|
): {
|
||||||
expandedKeys: Key[]
|
expandedKeys: Key[]
|
||||||
@ -26,6 +33,7 @@ export function keysWithFilter (
|
|||||||
const path: TreeOption[] = []
|
const path: TreeOption[] = []
|
||||||
traverse(
|
traverse(
|
||||||
nodes,
|
nodes,
|
||||||
|
childrenField,
|
||||||
(node) => {
|
(node) => {
|
||||||
path.push(node)
|
path.push(node)
|
||||||
if (filter(pattern, node)) {
|
if (filter(pattern, node)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user