使用地图键的React-Native隐藏组件

时间:2018-09-12 07:44:40

标签: react-native

我想隐藏通过键单击组件时。 我该怎么办?

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>
            );
        });

1 个答案:

答案 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>
            );
   }        
});