javascript - React JS - 获取当前可见的数组中的所有 dom 元素 id
问题描述
我试图获取在父视图组件内的地图中呈现的卡片组件的 ID。
我想要做的是获取数组中可见卡的所有 id 以进行 api 调用。
我不明白如何在 React 中做到这一点。任何帮助,将不胜感激。
class ParentView extends Component {
constructor(props) {
super(props);
this.state = {
idList: [],
}
}
componentDidMount() {
this.props.getData();// Fetch necessary data and store in redux
}
render(){
this.props.data.map((item, index)=>{
<ChildComponent key={index} renderData={item}/>
}
}
}
在上面的代码片段中,当它呈现它时,它会从 0 到 300 多张卡片中获取我。它以每行 6 张卡片的网格视图呈现。
每张卡都有一个与之关联的 id。我需要知道的是,当我滚动浏览父视图时,我需要使用当前在 View Port 中的 ChildComponent 的 id 更新状态 idList。
我不知道如何在 React JS 中实现这一点。
我曾尝试使用https://www.npmjs.com/package/react-in-viewport但无助于获取 ChildComponent 的 id。
解决方案
推荐阅读
- android - Android Studio:可绘制文件夹添加子目录或创建新文件夹问题
- c++ - C++ Blackjack 代码只执行第一个 if 语句
- wordpress - 手机版图片居中
- kotlin - 购买完成后 UI 元素更新不起作用 - Google 计费客户端 4
- react-native - 从 react native 获取 API 调用中的 csrf 问题
- opencv - 图像中边界框的坐标
- php - 使用“AWS Cloudfront”CDN 配置时,“搜索”选项在“Wordpress”中不起作用
- javascript - 如何使用 axios 将数组发送到服务器
- python - Django 中的登录和身份验证
- html - 摆脱未知的溢出 CSS