【问题标题】:Email SQLite data React Native电子邮件 SQLite 数据 React Native
【发布时间】:2022-01-15 13:37:13
【问题描述】:

我需要在我的 react 本机应用程序中通过电子邮件发送来自 SQLite 的数据。我希望 SQLite 中的数据位于电子邮件正文中

这是我目前得到的:

  const getSqliteData = () => {
    db.transaction(
      (tx) => {
        tx.executeSql("select * from cart", [], (_, { rows }) =>
           JSON.stringify(rows)
        );
      }
    );
  };

  return (
    <SafeAreaView style={{ flex: 1 }}>
      <View style={{ flex: 1, backgroundColor: "white" }}>
        
// some other stuff

            <TouchableOpacity style={styles.buttonsend} onPress={ () => {
              sendEmail(
                '',
                '',
                'This was sent from my-app -- ' + getSqliteData,
             { cc: '' }
            ).then(() => {
                console.log('Your message was successfully sent!');
            })
            }}>
            <Text style={styles.buttontext}>Email</Text>
            </TouchableOpacity>

它不会抛出任何错误,只是不返回任何数据。

谢谢

【问题讨论】:

    标签: android ios react-native expo


    【解决方案1】:

    万一有人还在寻找答案。

    1. 声明一个状态let [flatListItems, setFlatListItems] = useState([]);

    2. 从 SQLite 中提取数据

         db.transaction((tx) => {
       tx.executeSql("select * from cart", [], (tx, results) => {
         var temp = [];
         for (let i = 0; i < results.rows.length; ++i)
           temp.push(results.rows.item(i));
         setFlatListItems(temp);
       });
      
    3. 将数据传递到电子邮件正文sendEmail('','','This was sent from my-app -- ' + JSON.stringify(flatListItems, ['name', 'qty']),{ cc: '' })

    【讨论】:

      猜你喜欢
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 2022-12-04
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多