React native 在屏幕上显示值,但不在警报框中 \u按ButtonPost(){ 获取(“url”{ 方法:“张贴”, 标题:{ “接受”:“应用程序/json”, “内容类型”:“应用程序/json”, }, 正文:JSON.stringify({“entryDate”:“2017年3月2日凌晨2:00”,“dia”:“808”,“mobileType”:“ANDROID”,“用户名”:“menutest”})}) .then((response)=>response.json()) .然后((响应数据)=>{ 警惕,警惕( “血压数据”, “血压数据-”+JSON.stringify(responseData) ) }) .完成(); } _onPressButtonGET(){ 获取(“url”{ 方法:“张贴”, 标题:{ “接受”:“应用程序/json”, “内容类型”:“应用程序/json”, }, 正文:JSON.stringify({“mobileType”:“ANDROID”,“userName”:“menutest”}) .then((response)=>response.json()) .然后((响应数据)=>{ 警惕,警惕( “血压数据”, “血压数据-”+JSON.stringify(responseData) ) }) .完成(); } render(){ 返回( 添加 显示 ); }

React native 在屏幕上显示值,但不在警报框中 \u按ButtonPost(){ 获取(“url”{ 方法:“张贴”, 标题:{ “接受”:“应用程序/json”, “内容类型”:“应用程序/json”, }, 正文:JSON.stringify({“entryDate”:“2017年3月2日凌晨2:00”,“dia”:“808”,“mobileType”:“ANDROID”,“用户名”:“menutest”})}) .then((response)=>response.json()) .然后((响应数据)=>{ 警惕,警惕( “血压数据”, “血压数据-”+JSON.stringify(responseData) ) }) .完成(); } _onPressButtonGET(){ 获取(“url”{ 方法:“张贴”, 标题:{ “接受”:“应用程序/json”, “内容类型”:“应用程序/json”, }, 正文:JSON.stringify({“mobileType”:“ANDROID”,“userName”:“menutest”}) .then((response)=>response.json()) .然后((响应数据)=>{ 警惕,警惕( “血压数据”, “血压数据-”+JSON.stringify(responseData) ) }) .完成(); } render(){ 返回( 添加 显示 ); },react-native,alert,fetch,React Native,Alert,Fetch,我可以将值存储到数据库中并将其取回,但我正在警报框中显示这些值,但我想在屏幕上显示,每当我单击“显示”按钮时,如何编辑代码以在屏幕上显示entryDate和dia?使用状态- _onPressButtonPOST(){ fetch("url", { method: "POST", headers: { 'Accept': 'application/json',

我可以将值存储到数据库中并将其取回,但我正在警报框中显示这些值,但我想在屏幕上显示,每当我单击“显示”按钮时,如何编辑代码以在屏幕上显示entryDate和dia?

使用
状态
-

 _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>
            );
    }
构造函数(道具){
超级(道具);
此.state={
数据:“”
};
}
_onPressButtonGET=()=>{
....
.然后((响应数据)=>{
这是我的国家({
数据:JSON.stringify(responseData)
})
})
}
render(){
返回(
.....
.....
{this.state.data}
);
}

获取错误,如“undefined不是一个函数(评估'this2.setState({data:responseData})))更改
\onPressButtonGET(){
\onPressButtonGET=()=>{
。胖箭头函数自动绑定
。这不起作用,单击“显示未发生任何事情”。{this.state.data}它显示的是同一行,而不是数据。我想您有
this.state.data
。将其更改为
{this.state.data}
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>
  );
}