I am extracting data from a JSON Array and creating objects out of it and setting the string values that I need from the array within the objects I am creating using a for
loop:
var gamesList = [];
gamesList = this.props.navigation.state.params.gamesList;
var gameIconList = [];
for(var i=0;i<3;i++){
var provider = gamesList[i].provider;
var gameId = gamesList[i].gameId.toString();
gameIconList.push(
<TouchableOpacity onPress={(provider,gameId) => this.launchGame(provider,gameId)}>
<ResponsiveImage source={{uri: gamesList[i].imageUrl}}
initWidth="200" initHeight="120" defaultSource={require('./splash-tile2.png')} />
</TouchableOpacity>
);
}
This is all happening within the render()
function and the {gameIconList}
will be called in the return()
function as below:
return(
<ScrollView horizontal={true}>
{gameIconList}
</ScrollView>
);
As you can see I am setting the string values into the onPress function call via the loop and when I click the image within the TouchableOpacity
I want the string values I am setting to be sent back to the function above which is:
launchGame = (provider, gameId) => {
params = {
Provider: provider.nativeEvent.text,
Platform: this.state.Platform,
Environment: this.state.Environment,
GameId: gameId,
IsDemo: this.state.IsDemo
};
request = {
method: 'POST',
headers:{
"Content-Type": "application/json"
},
body: params
};
}
But the problem is I have tried so many different methods and I always end up getting a Proxy object sent back to me when it comes to the provider value and an undefined sent to me when it comes to the gameId value.
I have tried the calling method of event.target.value
and event.nativeEvent.text
but to no avail.
What am I missing? And if this is not the correct way of sending values to the function, can I get a guide on how to do it properly?