【发布时间】:2019-12-14 00:41:39
【问题描述】:
我已经创建了我的下拉菜单,但不幸的是它从 API 收到了重复的值。我从 BE 收到一定数量的文件,其中一些具有相同的名称,因此在我的下拉列表中我收到了重复的名称。我的代码如下所示:
我的功能
divideItems = () => {
let startIndex = ((parseInt(this.state.activePaginationTab) + 1) * this.state.rowsPerPage) - this.state.rowsPerPage;
let endIndex = (parseInt(this.state.activePaginationTab) + 1) * this.state.rowsPerPage - 1;
let tabItems = [];
for (let i = startIndex; i <= endIndex; i++) {
if (this.state.items[i]) {
tabItems.push(this.state.items[i]);
}
}
this.setState({
tabItems: tabItems
}, () => {
});
我的渲染
<RBS.Dropdown>
<RBS.Dropdown.Toggle id="dropdown-invoice-header">
{translations.type}
</RBS.Dropdown.Toggle>
<RBS.Dropdown.Menu>
{this.state.tabItems.map(item => (
<RBS.Dropdown.Item >{item.documentType}</RBS.Dropdown.Item>
))}
</RBS.Dropdown.Menu>
</RBS.Dropdown>
结果在我的下拉菜单中重复项目。
【问题讨论】:
-
state.tabItems中是否也有重复条目? -
是的,因为它是一张桌子,我使用
state.tabItems也更进一步。
标签: javascript arrays reactjs api