【问题标题】:How to display link from MySQL DB table in react native如何在本机反应中显示来自 MySQL DB 表的链接
【发布时间】:2019-12-08 05:51:18
【问题描述】:

我正在尝试以本机反应从 MySql 数据库中获取数据。为此,我将 MySql 数据库表转换为 json,我正在获取数据。但是我的 MySQL 表中有一个包含 url 或链接的字段。我已经获取了所有的文本数据。 现在我在从 json 文件中获取链接时遇到问题。

就像在 PHP 中一样,我们是这样获取它的

<button onclick="window.open('<?php echo $row["url"]; ?>')" >Website</button>

但我不知道如何从 json 文件中获取链接。 我试图这样做 -

<Button onPress={() => { Linking.openURL('rowData.url') }} > //here url is a field name
    Website
 </Button>

但是,它不起作用。

【问题讨论】:

  • 我听不懂你说什么!请使用状态,然后将其传递给 openURL 函数以打开网页!

标签: mysql json react-native


【解决方案1】:

试试这个:

import rowData from './test.json'
//...
//...
<Button onPress={() => { Linking.openURL(rowData.url) }} > //here url is a field name
    <Text> Website </Text>
</Button>

【讨论】:

  • 我已经更新了我的问题..希望你现在能理解
【解决方案2】:

你必须先把文件的内容解析成一个JSON对象,然后才能得到url属性。在不了解代码的情况下,它应该看起来像这样。

onPress={() => { JSON.parse(Linking.openURL('rowData')).url }} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-23
    • 2019-01-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多