import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Navigator,
TouchableOpacity,
Image,
TextInput,
TouchableHighlight,
Alert
} from 'react-native';
import Button from 'react-native-button'
import {Actions} from 'react-native-router-flux'
import Home from './Home'
export class Weight extends Component{
constructor(props) {
super(props);
this.state = {
data: '',
data1:'',
textinput:'',
entryDate: '',
systol:''
}
componentDidMount(){
this._onPressButtonGET();
}
_onPressButtonPOST(){
fetch("url", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"entryDate":"3/2/2017 2:00 AM",
"systol": "120",
"mobileType":"ANDROID",
"userName":"menutest"
})})
.then((response) => response.json())
.then((responseData) => {
Alert.alert(
"Blood pressure data",
"Blood pressure data - " + JSON.stringify(responseData)
)
})
.done();
}
_onPressButtonGET () {
fetch("url", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({"mobileType":"ANDROID","userName":"menutest"})})
.then((response) => response.json())
.then((responseData) => {
this.setState({ data: JSON.stringify(responseData) })
})
.done();
}
render(){
return(
<View>
<TouchableHighlight onPress={this._onPressButtonPOST}>
<Text>Add</Text>
</TouchableHighlight>
<TouchableHighlight onPress={this._onPressButtonGET.bind(this)}>
<Text>show</Text>
</TouchableHighlight>
<Text>{this.state.responseData.entryDate}</Text>
<Text>{this.state.responseData.systol}</Text>
<Text>hello{this.state.data}</Text>
</View>
);
}
}
module.exports = Weight;
I want to display only systol and entryDate on the screen, but my above code is displaying all the data from web services, How can i edit my code that i want to display only those things? i tried with this.setState({ data: responseData.entryDate }) but this is not working need help. and how to use for loop in _onPressButtonGET() to display all entry dates and systol.