在屏幕上显示值,但不在警报框中显示值


 _onPressButtonPOST(){
        fetch("url", {
            method: "POST",
             headers: {
                 'Accept': 'application/json',
                 'Content-Type': 'application/json',
             },
            body: JSON.stringify({"entryDate":"3/2/2017 2:00 AM","dia":"808","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) => {
            Alert.alert(
                "Blood pressure data",
                "Blood pressure data - " + JSON.stringify(responseData)
            )
    })
        .done();
    }

    render(){
        return(
            <View>

          <TouchableHighlight onPress={this._onPressButtonPOST} >
                    <Text>Add</Text>
                </TouchableHighlight>
                 <TouchableHighlight onPress={this._onPressButtonGET} >
                    <Text>show</Text>
                </TouchableHighlight>

            </View>
            );
    }

我能够将值存储到数据库中并将其拿回去,但是我在警报框中显示这些值,但我想在屏幕上显示,如何编辑我的代码以在屏幕上显示entrydate,并在屏幕上显示DIA,显示按钮?

使用state-

constructor(props) {
  super(props);
  this.state = {
    data: ''
  };
}
_onPressButtonGET = () => {
  ....
  .then((responseData) => {
    this.setState({
      data: JSON.stringify(responseData)
    })
  })
}
render() {
  return(
    <View>
      .....
      .....
      <Text>{this.state.data}</Text>
    </View>
  );
}

相关内容

  • 没有找到相关文章

最新更新