【问题标题】:Problems with reactstrap carousel indicatorsreactstrap 轮播指示器的问题
【发布时间】:2018-04-29 19:38:56
【问题描述】:
<Carousel
  activeIndex={this.state.activeIndex}
  next={this.next}
  slide
  previous={this.previous}
>
  <CarouselIndicators
    items={this.items.map(item => item.id)}
    activeIndex={this.state.activeIndex}
    onClickHandler={this.goToIndex}
  />
  {this.items.map(item => {
    return (
      <CarouselItem
        onExiting={this.onExiting}
        onExited={this.onExited}
        key={item.id}
        src={item.images.big}
        altText={item.name}
      />
    );
  })}
  <CarouselControl
    direction="prev"
    directionText="Назад"
    onClickHandler={this.previous}
  />
  <CarouselControl
    direction="next"
    directionText="Вперёд"
    onClickHandler={this.next}
  />
</Carousel>

我有一个来自此示例 reactstrap carousel 的引导轮播组件。但是当它呈现我得到错误:

遇到两个孩子用同一个钥匙,undefinedundefinedundefined。密钥应该是唯一的,以便组件在更新时保持其身份。非唯一键可能会导致子项被复制和/或省略——这种行为不受支持,并且可能在未来的版本中发生变化。 in ol(由 CarouselIndicators 创建)

但“CarouselIndicators”项目是唯一值。谁能解释我哪里错了?

【问题讨论】:

  • 在您的 items 数组中似乎有些对象的 id 未定义,请确保您有唯一的 item 值

标签: reactjs bootstrap-4 reactstrap


【解决方案1】:

这是一个反应带问题。您传递给的数组必须是其中包含字段 'src' 的对象数组,如下所示:

[{src: 'unique string', ...}]

由于&lt;CarouselIndicators /&gt; 使用数组项中的字段“src”作为其项的键

【讨论】:

  • 你能澄清一下你的意思吗?
  • 基本上,您传递给 的数组必须是一个包含对象的数组,并且这些对象必须有一个名为 'src' 的键,并且该键的值必须是唯一的字符串,因为 需要这个键'src',但它不在文档中
猜你喜欢
  • 2015-09-28
  • 2019-06-18
  • 2019-07-01
  • 2020-01-02
  • 2015-08-13
  • 2019-02-28
  • 2019-06-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多