0

之前遇到一个错误:
Warning: Encountered two children with the same key,project. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.

这个错误来自我一直在使用的 Grommet DataTable。问题在我的桌子上,第一列是“类型”,它可以有两个选项之一:项目或任务。Grommet 自动将第一列作为键,这不是我想要的,因为键会重复。

我已经彻底阅读了 Grommets 文档,并尝试按照他们在此处的指示输入主键:

https://v2.grommet.io/datatable#primaryKey

我的第一次尝试是按照他们的指示使用 primaryKey,请参阅下面代码中的第一次尝试。

我的第二次尝试是将 data._id 作为列输入,并将主要设置为 true。这可行,但我不希望 data._id 显示在我的表中,我只想将其设置为键。


`<DataTable
    sortable={true}
//this is what I attempted but nothing happened
    primaryKey={data._id}
    columns={columns}
    data={data}
/>`


我想将键设置为 data._id,因为它是唯一标识符,但是,我不希望 data._id 显示在我的表中。

任何建议将不胜感激。

4

1 回答 1

1

primaryKey 需要是一个字符串,所以在这种情况下,它将是:

`<DataTable
    sortable={true}
    primaryKey="_id"
    columns={}
  />`
于 2019-04-14T16:26:08.973 回答