如何通过React中的多个视频按钮按钮onclick事件
使用fetch
调用API并在控制台中获取响应,然后将值分配给表标头。 之后,在React Js中创建一个按钮。每个按钮都有一个视频URL,该视频URL来自API响应
API响应:
Camera_Number:"Camera_1"
Group_Name: "Group_1"
Video_Name: "http://localhost:4000/video/0"
Camera_Number:"Camera_2"
Group_Name: "Group_2"
Video_Name: "http://localhost:4000/video/1"
我将此响应存储在usestate
中,然后将此usestate响应传递给视频播放器源上方代码
const actionButton = (params) => {
setVideoName(response.videoName); // How to update videoName here
setOpen(true);
};
const [videoName, setVideoName] = useState([]);
const [response, setResponse] = useState([]);
headerName: "Actions",
field: "Video_Name",
cellRendererFramework: (params) => (
<div>
<Button
variant="contained"
onClick={() => actionButton(params)}
>
Play
</Button>
</div>
上面的code show dission_name到action> actions
标题然后创建一个按钮。当我单击一个按钮时,所有视频都会在一个窗口中打开并播放所有视频。但是我想要它,以便只有点击的某些视频才能显示。
<DialogContent>
{response.map(({ Video_Name }) => (
<iframe
width="420"
height="315"
title="videos"
src={Video_Name}
/>
))}
</DialogContent>
如何使用React-Hooks解决此问题。
有关更多详细信息和代码参考
如何为视频和视频和视频创建索引将视频传递给视频播放器来源。当我单击该按钮时,单击某些视频将显示。
谢谢
call API using fetch
and get response in console and assign values to table header.
after that creating one button in react js. Each button have one video URL which is got from API response
API response:
Camera_Number:"Camera_1"
Group_Name: "Group_1"
Video_Name: "http://localhost:4000/video/0"
Camera_Number:"Camera_2"
Group_Name: "Group_2"
Video_Name: "http://localhost:4000/video/1"
I stored this response in useState
and pass this usestate response to video player source
const actionButton = (params) => {
setVideoName(response.videoName); // How to update videoName here
setOpen(true);
};
const [videoName, setVideoName] = useState([]);
const [response, setResponse] = useState([]);
headerName: "Actions",
field: "Video_Name",
cellRendererFramework: (params) => (
<div>
<Button
variant="contained"
onClick={() => actionButton(params)}
>
Play
</Button>
</div>
Above code shows assign video_name to Actions
header then I created one button. when I click one button, all of the videos open in one window and play all videos. But I want it so that only that certain video that was clicked would show.
<DialogContent>
{response.map(({ Video_Name }) => (
<iframe
width="420"
height="315"
title="videos"
src={Video_Name}
/>
))}
</DialogContent>
How to resolve this issue using react-hooks.
for more details and code reference
how to create index for video and pass videos to video player source. when i click that button certain video that was clicked would show.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需使用按钮的点击处理程序。您无法获得行数据。
将
colid
添加到操作列定义。然后处理网格的操作。您可以使用params.node.data
获取行数据。No need to use the click handler of the button. You cannot get row data with that.
Add a
colId
to column definition for actions. Then handle theonCellClicked
action of the grid. You can get the row data usingparams.node.data
.Codesand box Link
更新答案:
首先,您必须安装 json-loader
之后,您可以动态导入。
(使用React Hooks代码演示,对类组件进行相同的操作)
Update answer:
First, you have to install json-loader
After that, You can use dynamically import.
(code demo using React Hooks, do the same with class component)