Primereact:警告:遇到两个具有相同密钥的孩子,

问题描述

我正在使用引物下拉列表https://primefaces.org/primereact/showcase/#/dropdown

但收到此警告:-

react_devtools_backend.js:2450警告:遇到两个具有相同密钥的孩子。密钥应该是唯一的,以便组件在更新中保持其身份。非唯一键可能会导致子代重复和/或被忽略-该行为不受支持,并且可能在将来的版本中更改。
在ul中(由DropdownPanel创建)
在div中(由DropdownPanel创建)

this.cities = [
            { name: 'Apple',code: '1' },{ name: 'Rome',code: '2' },code: '3' },{ name: 'Paris',code: '4' },code: '5' }
        ];

<Dropdown 
    value={this.state.selectedCity1} 
    options={this.cities} 
    onChange={this.onCityChange} 
    optionLabel="name" 
    placeholder="Select a City" />

如何在引文下拉菜单解决此问题。

解决方法

也许您应该添加optionValue="code"

<Dropdown
  value={this.state.selectedCity1}
  options={this.cities}
  onChange={this.onCityChange}
  optionLabel="name"
  optionValue="code"
  placeholder="Select a City"
/>