react 修改循环列表的当前单个子项状态:思路 拿原始state数据更改,再做请求
handleLike(item,index){ var id = item.id; _ENV.post( _ENV.HOST+'/communion/video-up', {'user_id':localStorage.getItem('uid'),'video_id':id} ).then(res => { let data = this.state.data; item.is_dz ? item.is_dz = false : item.is_dz = true; item.is_dz ? item.up += 1 : item.up -= 1; this.setState({ data:data }); }).catch(error=>{ console.log(error); }); }
{ this.state.data.map((item,index)=>
<VideoCard key={index}
name={item.staff_name}
personlink={'/personalcenter/'+item.created_uid}
videoId = {item.id}
color={item.is_dz ? 'active iconfont icon-xihuan' : 'iconfont icon-xihuan1'}
click={()=>this.handleLike(item,index)}
up={item.up}
number={item.num}
thumb={_ENV.HOST+'/'+item.staff_head_img}
time={item.time}
src={_ENV.HOST+'/'+item.thumb}
description={item.summary}/>
) }