react-native 自制多选功能

//多选js部分
changeMoreSelect =(index) =>{
const set = new Set(this.state.changeArr)
set.has(index) ? set.delete(index) : set.add(index)
//通过下标查询,如果set返回true则删除,反之则添加下标
this.setState({changeArr: [...set]},()=>{
console.log(this.state.changeArr)
})
}
// view层
{this.state.answer.map((item,index) =>{
//循环数组
return(
<TouchableOpacity key={index} style={{paddingLeft:15,marginTop:33}} onPress={()=>this.changeMoreSelect(index)}>
<View style = {{flexDirection:"row",alignItems:"center",}}>

//判断下标显示点击图片切换
{this.state.changeArr.indexOf(index) === -1 ?
<Image style={{width:14,height:14}} source={require("../../assets/images/changeOff.png")}/>:
<Image style={{width:14,height:14}} source={require("../../assets/images/changeOn.png")}/>
}

{/A/}
{item.a_text}


)
}

posted @ 2018-10-10 15:50  -http  阅读(658)  评论(0编辑  收藏  举报