简体   繁体   English

在具有其他映射参数索引的数组对象中映射

[英]map in array object with index of other map parameter

this is my code: 这是我的代码:

{seasons.map(k => (
    <TabPanel key={k} className="list-episode">
         <Scrollbars style={{ height: this.state.screenSize }}>
             {arrEpisodes[k].map(i => (
                  <div key={i.ID} className="episode">

but, the line {arrEpisodes[k]... not work, why? 但是,行{arrEpisodes [k] ...不起作用,为什么?

Change 更改

    {seasons.map(k => (
<TabPanel key={k} className="list-episode">
     <Scrollbars style={{ height: this.state.screenSize }}>
         {arrEpisodes[k].map(i => (
              <div key={i.ID} className="episode">

To

  {seasons.map((k, index)=> (
<TabPanel key={k.ID} className="list-episode">
     <Scrollbars style={{ height: this.state.screenSize }}>
         {arrEpisodes[index].map(i => (
              <div key={i.ID} className="episode">

The issue here is you are using data as index position to arrEpisodes array instead of index and that's why it fails. 这里的问题是您将数据用作arrEpisodes数组的索引位置而不是索引,这就是为什么它失败的原因。 You need to pass index of seasons array to arrEpisodes array. 您需要将Seasons数组的索引传递给arrEpisodes数组。 Also set id as key to TabPanel instead of Object Ie, k in your code 还要将id设置为TabPanel的键,而不是代码中的Object Ie,k

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM