如何动态更改<Text>值React Native

时间:2019-11-21 16:24:52

标签: react-native

我正在使用本机反应。我想根据我在MYSQL中获取的数据来更改“渲染”中的文本数据。当ItemDURUM = 0时,表示订单待定;当itemDURUM = 1时,表示订单已确认。目前0和1值正在等待订单的文本值正在等待。问题是什么?现在,我可以毫无问题地从MYSQL中提取变量0和1

export default class usrFirst extends React.Component {

import React, { Component } from "react";
import {  Text } from 'react-native';
import { Cell, Section, TableView } from 'react-native-tableview-simple';


    constructor(props) {
            super(props)
            this.state = {
         itemDURUM:[]
    }
      responseMUSTERISIPARISDURUM() {
    fetch('http://....php', {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({

        BOYLAM: this.state...,
        ENLEM: this.state....

      })

    }).then((response) => response.text())
          .then((responseJson) => {

           if(responseJson.length > 0)
            {
                 this.setState({itemDURUM : responseJson});

        }
          }).catch((error) => {
            console.error(error);
          });
     }
    render() {
    return (
    <Cell cellStyle="RightDetail" title=<Text style={{color:'#00a7c0',fontWeight: "bold"}}>Durum</Text> detail= { this.state.itemDURUM === '0'? <Text style={{color:'#0094ff',fontWeight: "bold"}}>Order Pending</Text>: <Text style={{color:'#ff1706',fontWeight: "bold"}}>Order Confirmed</Text>} />
    }
}

1 个答案:

答案 0 :(得分:-1)

您的渲染方法存在一些问题。我不确定您在哪里调用responseMUSTERISIPARISDURUM,但尝试将您的渲染方法更改为

content
相关问题