M
M
Maxim2015-12-28 19:00:01
JavaScript
Maxim, 2015-12-28 19:00:01

How to select a specific element (React Native)?

There is a "delete" button and 3 photos, when you click on one of the photos, text should appear next to it + the photo itself should be framed + when you click on "delete", the selected photo should be deleted.
Here I am interested in how to write one function for these three photos (it is impossible to register a function for each photo in onPress, because there can be any number of them) + how to determine when you click on "delete" that you need to delete this particular photo.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman_Kh, 2015-12-31
@might

Apparently you need bind :

handlePress(photoNo){
    // do something with photo number photoNo
    ....
}
....
render(){
    ....
    <TouchableHighlight onPress={this.handlePress.bind(this, photoNo)}>
      <Image style={...} source={...} />
    </TouchableHighlight>
    ....
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question