简体   繁体   English

在 ReactNative 应用程序中显示 MySQL 数据

[英]Displaying MySQL data in a ReactNative application

I want to display the data from my MySQL database, in my React Native application.我想在我的 React Native 应用程序中显示来自我的 MySQL 数据库的数据。

I am able to display the data in an alert message.我能够在警报消息中显示数据。 But not in the application (for example, in a tag).但不在应用程序中(例如,在标签中)。

How to do it?怎么做?

The screenshot represents the display of data in an alert message: alert message屏幕截图表示警报消息中数据的显示:警报消息

Thanks a lot!非常感谢!

You should use a Text component and access the object's comment_test property from it.您应该使用 Text 组件并从中访问对象的 comment_test 属性。

Without further code, I can only provide an example:没有更多的代码,我只能提供一个例子:

<View>
<Text>{mysqlResponseObject.comment_test}</Text>
<View>

Store the data in a state then iterate through it.将数据存储在 state 中,然后遍历它。 Use can update your state with setData function where you read the data from the database.使用可以更新您的 state 与 setData function 从数据库中读取数据。

    import React, { useState } from 'react';
    
    function Example() {
      const [data, setData] = useState([]);
    
      return (
        <View>
          {data.map((item) => (
            <Text>{item.comment_test}</Text>
          ))}
        </View>
      );
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM