【问题标题】:Primereact: Warning: Encountered two children with the same key,Primereact:警告:遇到两个孩子用相同的钥匙,
【发布时间】:2021-02-22 12:29:22
【问题描述】:

我正在使用 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' },
            { name: 'Rome', code: '3' },
            { name: 'Paris', code: '4' },
            { name: 'Paris', code: '5' }
        ];

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

如何在 primereact 下拉菜单中解决此问题。

【问题讨论】:

    标签: reactjs primereact


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2017-12-15
      相关资源
      最近更新 更多