如何在React Native中从平面列表中的SQLite数据库检索数据?

时间:2020-04-06 20:40:50

标签: javascript react-native expo

getLocalDBData = () => {
  let SQLcmd = "SELECT * FROM" + localDB.tableName.Employee+ " WHERE Name LIKE "+ this.state.EName;
  console.log(SQLcmd)
  db.transaction(tx => {
    tx.executeSql(
      SQLcmd,
      [],
      (tx, results) => {
        var len = results.rows.length;
        if (len > 0) {
          for (let i = 0; i < len; i++) {
            let row = results.rows.item(i);
            console.log("Employee Id:" + row.Name);
            // this.setState({output:row.Name})
            this.setState((prevState) => ({ data : prevState.data.push(row.Name)}))
          }
        }
        // Get rows with Web SQL Database spec compliance.
        /*let rows = results.rows.raw();
        this.setState({ data: rows })*/
      }
    );
  });
}

0 个答案:

没有答案