如何在响应本机中传递调用api的ID或按图片获得唯一ID?

时间:2019-02-14 11:14:25

标签: javascript reactjs react-native

  <ScrollView horizontal pagingEnabled snapToInterval={200}>
              {this.state.json_arr.map((item, index) => (
                <View

                  key={item.user_id}
                  style={{
                    paddingBottom: 40,
                    justifyContent: "center",
                    alignItems: "center",
                    padding: 5
                  }}
                >
                  <TouchableOpacity onPress={this.fullsize_image}>
                    <Image

                    source={{ uri: this.state.url + item.image }}
                    style={{ width: 380, height: 400 }}
                    />
                  </TouchableOpacity>
                  <View
                    style={{
                      flexDirection: "row",
                      paddingBottom: 50,
                      position: "absolute",
                      top: 0,
                      marginTop: 320,
                      left: 0,
                      right: 0,
                      bottom: 0,
                      justifyContent: "center",
                      alignItems: "center"
                    }}
                  >
                    <Text style={{ color: "white", fontSize: 22 }}>
                     {item.user_id}.
                    </Text>
                    <Text style={{ color: "white", fontSize: 22 }}>
                      {item.age}.
                    </Text>
                    <Text
                      style={{ color: "red", paddingLeft: 5, fontSize: 22 }}
                    >
                      {item.nick_name}
                    </Text>
                    <Text
                      style={{ color: "red", paddingLeft: 5, fontSize: 22 }}
                    >
                      {" "}
                      {item.user_location}
                    </Text>
                  </View>
                </View>
              ))}
            </ScrollView>

在上面的代码中,我映射了一个数组并获取了诸如image,user_id等之类的数据,但我需要将用户设置为使用该ID调用另一个api的状态。假设当我按下图像时,生成的该图像的ID大于该ID并传递给调用api。下面我附加了一个图像,该图像中有注释,如对特定图像的注释比注释应为该user_id保存选项avaiale。因此,请指导如何为此做逻辑。

plese view this

1 个答案:

答案 0 :(得分:0)

就在Tag上,它编写了一个函数来承载事件处理程序函数,该函数随后调用一个util将该ID发送给API,如下所示:

<Image onPress = {() => api.sendToAPI(item.id);}
            source={{ uri: this.state.url + item.image }}
                style={{ width: 380, height: 400 }}

>