代码之家  ›  专栏  ›  技术社区  ›  Buwaneka Sudheera

在React Native app中显示数据库数据时遇到问题

  •  0
  • Buwaneka Sudheera  · 技术社区  · 8 年前

    componentWillMount() {
        fetch('http://bsthisarasinghe-001-site1.1tempurl.com/projectDetails.php', {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                job_code: this.props.navigation.state.params.code
            })
    
        }).then((response) => response.json())
            .then((responseJson) => {
                this.setState({ data: responseJson.results });
    
            }).catch((error) => {
    
                Alert.alert("No internet connection");
                this.setState({ loading: false });
            });     
    }
    

    这就是我在控制台上打印的方法。

    onFocus1() {
        console.log(this.state.data[0].Job_Code);
    }
    

    但当我试图在app中显示相同的字符串时,它显示了一个错误。

    我试过了。

     <View style={{ width: '35%' }}>
         <Text style={styles.textBoldStyle}>Project Name: </Text>
     </View>
     <View style={{ width: '65%' }}>
         <Text style={styles.textStyle}>{this.state.data[0].Job_Code}</Text>
     </View>
    

    “TypeError:无法读取未定义的属性'Job\u Code'”

    enter image description here

    我想将数据库数据单独添加到那些键入“something”的地方。

    0 回复  |  直到 8 年前
    推荐文章