I am trying to populate a Tree Select in ANT Design from API, the API Response type is so
projectData = ProjectData[];
export type ProjectData = {
key?: number;
projectId: number;
projectName: string;
description: string;
level: number;
parent: string;
parentId: number;
children: ProjectData[];
};
for TreeSelect I can't find an option to set title
to projectName
and value
to projectId
Tree select takes treeData
values in this format
const treeData = [
{
title: 'Node1',
value: '0-0',
children: [
{
title: 'Child Node1',
value: '0-0-1',
},
{
title: 'Child Node2',
value: '0-0-2',
},
],
},
{
title: 'Node2',
value: '0-1',
},
];
For example if I am using a a Cascader in ant design I can set the mapping with the fieldNames
prop like so
fieldNames={{ label: 'projectName', value: 'projectId', children: 'children' }}
is it possible at all to do something like this with TreeSelect?
I have a ProjectData[]
as mentioned above and I need to generate a tree select using that data. What is the best way?
Now If I use Cascader I can only select the Last(deepest) entry and not a node which is a parent. Thus I have to use Treeselect and Can't figure out how to map it properly.
------- Edit -----------
Added a sample of data with implementation of cascader and treeselect on codesandbox here
question from:
https://stackoverflow.com/questions/65909094/ant-design-treeselect-map-data-from-api-to-title-value-keys 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…