页面部分:
{this.state.answer.map((item,index) =>{
return(
<touchableOpacity key={index} onPress={()=>this.changeImage(index)}>
<View style = {{flexDirection:"row",alignItems:"center",paddingLeft:15,marginTop:33}}>
<View >
{index==this.state.index ?
<Image style={{14,height:14}} source={require("../../assets/images/changeOn.png")}/>:
<Image style={{14,height:14}} source={require("../../assets/images/changeOff.png")}/>
}
</View>
{/*<View style={{paddingLeft:14}}><Text>A</Text></View>*/}
<View style={{paddingLeft:10}}><Text>{item.a_text}</Text></View>
</View>
</touchableOpacity>
)
}
)}
touchableOpacity换大写T
js部分:
//多选
changeMoreSelect =(index) =>{
const set = new Set(this.state.changeArr)
set.has(index) ? set.delete(index) : set.add(index)
this.setState({changeArr: [...set]},()=>{
console.log(this.state.changeArr)
})
}