选择并上传图像数组

时间:2019-03-04 12:02:25

标签: react-native-android

如何在React Native中一一显示图像并上传到数据库

每个图像都应附加到数组并显示

1 个答案:

答案 0 :(得分:0)

将每个图像数据推送到数组

this.state.imageholder.push(response.data);

显示并删除

  viewImages() {

return this.state.imageholder.map((image, key) => {
  return (

    <View style={{ flex: 2, flexDirection: "row", justifyContent: 'space-around' }}>

      <View style={styles.ImageContainer}>
        <Image style={styles.ImageContainer} source={image} />
        <Text onPress={() => this.removeImage(image)} style={styles.removeContainer} >Remove</Text>
      </View>
      <View>
        <Text style={styles.space} ></Text>

      </View>
    </View>


  )
})

}

  removeImage(key) {
this.setState({
  imageholder: this.state.imageholder.filter(function (img) {
    return img !== key
  })
});

}

渲染中

              <ScrollView horizontal={true} showsHorizontalScrollIndicator={false}>

            {this.viewImages()}

          </ScrollView>