我想隐藏通过键单击组件时。 我该怎么办?
let departmentlist = this.state.departments.map((val,key) => {
return (
<View key={key}>
<TouchableOpacity style={styles.departmentcontainer}>
<Text style={styles.departmentname}>{val.department}</Text>
</TouchableOpacity>
<View>
{userlist}
</View>
</View>
);
});
答案 0 :(得分:0)
this.state ={
hide_keys: []
}
let departmentlist = this.state.departments.map((val,key) => {
if(this.state.hide_keys.include(key) {
return null;
} else {
return (
<View key={key}>
<TouchableOpacity style={styles.departmentcontainer} onPress={()=> this.setState({hide_keys: [...this.state.hide_keys, key]})}>
<Text style={styles.departmentname}>{val.department}</Text>
</TouchableOpacity>
<View>
{userlist}
</View>
</View>
);
}
});