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
|
||||
|
||||
- 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)
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
## 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)
|
||||
|
||||
|
@ -374,6 +374,7 @@ export default defineComponent({
|
||||
props.data,
|
||||
props.pattern,
|
||||
props.keyField,
|
||||
props.childrenField,
|
||||
mergedFilterRef.value
|
||||
)
|
||||
uncontrolledHighlightKeySetRef.value = highlightKeySet
|
||||
|
@ -2,12 +2,18 @@ import { Key, TreeOption } from './interface'
|
||||
|
||||
function traverse (
|
||||
nodes: TreeOption[] | undefined,
|
||||
childrenField: string,
|
||||
callback: (node: TreeOption) => void,
|
||||
callbackAfter: (node: TreeOption) => void
|
||||
): void {
|
||||
nodes?.forEach((node) => {
|
||||
callback(node)
|
||||
traverse(node.children, callback, callbackAfter)
|
||||
traverse(
|
||||
(node as any)[childrenField],
|
||||
childrenField,
|
||||
callback,
|
||||
callbackAfter
|
||||
)
|
||||
callbackAfter(node)
|
||||
})
|
||||
}
|
||||
@ -16,6 +22,7 @@ export function keysWithFilter (
|
||||
nodes: TreeOption[],
|
||||
pattern: string,
|
||||
keyField: string,
|
||||
childrenField: string,
|
||||
filter: (pattern: string, node: TreeOption) => boolean
|
||||
): {
|
||||
expandedKeys: Key[]
|
||||
@ -26,6 +33,7 @@ export function keysWithFilter (
|
||||
const path: TreeOption[] = []
|
||||
traverse(
|
||||
nodes,
|
||||
childrenField,
|
||||
(node) => {
|
||||
path.push(node)
|
||||
if (filter(pattern, node)) {
|
||||
|
Loading…
Reference in New Issue
Block a user