admin管理员组文章数量:1334886
Is that possible navigate to previous item, inside a map using React, I would like to parer the actual iteration with before, if the before have different group, per example, I will show the new one.
I would like to do something like that:
{navigation.map((item, i) => {
return(
<li key={i}>
{i > 0 && item[i].groupName != item[i - 1].groupName && <div>Another group: {item[i].groupName}</div>}
</li>
)
})}
Is that possible navigate to previous item, inside a map using React, I would like to parer the actual iteration with before, if the before have different group, per example, I will show the new one.
I would like to do something like that:
{navigation.map((item, i) => {
return(
<li key={i}>
{i > 0 && item[i].groupName != item[i - 1].groupName && <div>Another group: {item[i].groupName}</div>}
</li>
)
})}
Share
Improve this question
edited Jan 31, 2018 at 23:13
asked Jan 31, 2018 at 23:06
user8321027user8321027
6
-
What is
before
? – zerkms Commented Jan 31, 2018 at 23:07 - the item before the actual in the loop, sorry for my english x( – user8321027 Commented Jan 31, 2018 at 23:10
- Then what does "navigate to the previous item" mean? – zerkms Commented Jan 31, 2018 at 23:10
- I tried show a code sample – user8321027 Commented Jan 31, 2018 at 23:10
- I would like to acces the previous item in the array, example items[1,2,3,4,5], my iteration if was in the third I would like to pare with the second, like my sample – user8321027 Commented Jan 31, 2018 at 23:13
1 Answer
Reset to default 7Yes, but it is not React-specific. It is JavaScript Array.map.
{navigation.map((item, i, arr) => {
const previousItem = arr[i - 1];
return(
<li key={i}>
{i > 0 && item[i].groupName != item[i - 1].groupName && <div>Another group: {item[i].groupName}</div>}
</li>
)
})}
本文标签: javascriptNavigating to previous item inside map in ReactStack Overflow
版权声明:本文标题:javascript - Navigating to previous item inside map in React - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742380560a2464003.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论