[英]Pass a Parameter to an onClick Function
I created a React single page application with the API from the NASA Picture of the Day and I added in a drawer a list with the history of the images displayed and it's is showing only its dates. 我使用NASA的每日图片API创建了一个React单页应用程序,并在抽屉中添加了一个列表,其中包含所显示图像的历史记录,并且仅显示其日期。
I have a Material-UI list item and I want to pass to its onClick
function a parameter. 我有一个Material-UI列表项,我想将一个参数传递给它的
onClick
函数。 I want that when I click on a specific date on the drawer to show me the image from that specific date. 当我在抽屉上单击特定日期以显示该特定日期的图像时,我希望这样做。
Here I want to pass the parameter index: 在这里我想传递参数索引:
pushDate = () => {
menu.dates.push(this.state.image.date);
index = menu.dates.indexOf(this.state.image.date);
menu.menuItems.push(
<List>
<ListItem onClick={this.handleClose} primaryText={this.state.image.date} leftIcon={<ImagePhoto />} />
</List>
);
}
And here is the handleClose function : 这是handleClose函数:
handleClose = (date) => {
this.setState({
open: false,
controlledDate: moment(menu.dates[index]),
});
this.getImage(moment(menu.dates[index]));
}
应该是onClick={() => this.handleClose(this.state.image.date)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.