我试图在react jsx块中读取mongodb默认的_id属性。但是我无法阅读它。我已经确认传递给功能组件ProductTableSingleRow
的行对象上存在_id键const ProductTableSingleRow = ({ row, index }) => (
<Table.Row key={row._id}>
<Table.Cell>{index}</Table.Cell>
<Table.Cell>{row.brandCode}</Table.Cell>
<Table.Cell>
{row.colorName} ({row.colorCode}) - {row.collectionName} ({row.collectionCode})
</Table.Cell>
<Table.Cell>
{row.skuSize} {row.skuType}
</Table.Cell>
<Table.Cell>{row.categoryCode}</Table.Cell>
<Table.Cell>{row.fabricType}</Table.Cell>
<Table.Cell>
<Button color="red">Delete</Button>
</Table.Cell>
</Table.Row>
);
我在控制台中一直低于错误
index.js:2178 Warning: Each child in an array or iterator should have a unique "key" prop. See ... for more information.
in ProductTableRows (at HomePage.js:64)
in tbody (created by TableBody)
in TableBody (at HomePage.js:63)
in table (created by Table)
in Table (at HomePage.js:51)
in div (created by Segment)
in Segment (at HomePage.js:50)
in div (at HomePage.js:47)
in HomePage (created by Route)
in Route (at App.js:7)
in div (at App.js:6)
in App (at index.js:10)
in Router (created by BrowserRouter)
in BrowserRouter (at index.js:9)
我错过了什么?
== update == 当我在Chrome中使用React Developer Tools时,我确实看到了_id值。见下图React Developer Tools Screenshot with key value
答案 0 :(得分:0)
如果仍然呈现表的内容,则可能有重复的行。尝试记录整个阵列或查看是否是这种情况。