antd treeselect发行'警告:树上存在相同的“值”:未定义'

发布于 2025-01-27 12:20:40 字数 463 浏览 3 评论 0原文

我的Treeselect组件发出警告:树上存在相同的“值”:未定义的警告但正确起作用,这是什么意思,我如何摆脱它?

const treeData = {
    id: 1,
    title: '1',
    children: [{
        id: 2,
        title: '2',
        parent_id: '1'
    }]
}
//-------
<Form.Item
    label={label}
    name={name}
>
    <AntdTreeSelect
        treeDataSimpleMode
        treeData={treeData}
    />
</Form.Item>

我正在使用ANTD 4.16.3

My TreeSelect component issuing a Warning: Same 'value' exist in the tree: undefined warning but works correctly, what does that mean and how do I get rid of it?

const treeData = {
    id: 1,
    title: '1',
    children: [{
        id: 2,
        title: '2',
        parent_id: '1'
    }]
}
//-------
<Form.Item
    label={label}
    name={name}
>
    <AntdTreeSelect
        treeDataSimpleMode
        treeData={treeData}
    />
</Form.Item>

I'm using antd 4.16.3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绳情 2025-02-03 12:20:40

事实证明,当使用treedatasimplemode prop时,treetElect期望对数据具有一定的结构,应该有一个pid指向父级,而treedata prop应该是平坦的阵列组件本身将从idpid s构建层次结构,因此将treedata更改为:

const treeData = [{
    id: 1,
    title: '1'
},{
    id: 2,
    title: '2',
    pId: '1'
}]

将解决问题;或者,您也可以向treedatasimplemode prop:

<AntdTreeSelect
    treeDataSimpleMode={{pId: 'parent_id'}}
    treeData={treeData}
/>

Note 提供有关您的结构的提示。 >,您必须在数据中具有value属性,但是您的数据结构可以是平坦的或树,它可以工作的任何一种方式

Turns out when using treeDataSimpleMode prop, the TreeSelect expect a certain structure to the data, there should be a pId pointing to a parent id and the treeData prop should be a flat array the component itself will build the hierarchy from id and pIds, so changing the treeData to:

const treeData = [{
    id: 1,
    title: '1'
},{
    id: 2,
    title: '2',
    pId: '1'
}]

will solve the problem; or alternatively you can give hints about your structure to the treeDataSimpleMode prop:

<AntdTreeSelect
    treeDataSimpleMode={{pId: 'parent_id'}}
    treeData={treeData}
/>

Note this is only limited to id and pid, you have to have a value property in your data, but your data structure can be flat or tree, it works either way

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文