Reactjs 我想在删除按钮点击图像的id
**我想要在Onclick中的特定图像的id。我们有一个包含所有图像数据的数组,即图像[]。如何将要删除的特定图像的id传递给deleteimage函数。欢迎任何建议或建议**Reactjs 我想在删除按钮点击图像的id,reactjs,Reactjs,**我想要在Onclick中的特定图像的id。我们有一个包含所有图像数据的数组,即图像[]。如何将要删除的特定图像的id传递给deleteimage函数。欢迎任何建议或建议** class Image extends Component { constructor() { super(); this.state = { images: [] }; } componentDidMount() { let result = apiGateway.getImag
class Image extends Component {
constructor() {
super();
this.state = { images: [] };
}
componentDidMount() {
let result = apiGateway.getImages();
if (result != null) {
result.then((value) => {
this.setState({ images: value.data.data });
});
}
}
deleteImage=()=>{
let result = apiGateway.removeImage(??);
}
renderImage(value,index){
let str = value.imagePath.split('/').pop();
let string = str.slice(0,-5);
return(
<div key={index}>
<p>Title: {value.title}</p>
<p>Description: {value.description}</p>
<button onClick={this.deleteImage}>DELETE</button>
<button>UPDATE</button>
<img className='image' src= {'http://localhost:3000/'+ string } width='100' height='100' alt='nature'/>
<br/><br/>
</div>
);
}
render() {
return(
<div>
<div>{
this.state.images.map((image,index)=>{
return this.renderImage(image,index);
})
}
</div>
</div>
);
}
}
export default Image;
类图像扩展组件{
构造函数(){
超级();
this.state={images:[]};
}
componentDidMount(){
让result=apiGateway.getImages();
如果(结果!=null){
结果。然后((值)=>{
this.setState({images:value.data.data});
});
}
}
deleteImage=()=>{
让结果=apiGateway.removeImage(;
}
渲染(值、索引){
让str=value.imagePath.split('/').pop();
设string=str.slice(0,-5);
返回(
标题:{value.Title}
描述:{value.Description}
删除
更新
);
}
render(){
报税表(
{
this.state.images.map((图像,索引)=>{
返回此.renderImage(图像、索引);
})
}
);
}
}
导出默认图像;
尝试发送值
至删除图像(值)
功能:
删除
或
this.deleteImage(值,e)}>DELETE
请查看更多