获取数据库中的数据并设置进度条的建议

问题描述

我已经在数据库中存储了学生 ID 和阅读的书籍数量。现在,我已经实现了获取学生阅读书籍数量的详细信息的方法。但函数 progressbardata() 不返回从查询中获取的数据。我试图在 db.transaction() 中手动分配一个值并返回它但没有运气。

你能告诉我我哪里做错了吗。这种方法也循环多次。我们如何解决这个问题。

import * as Progress from 'react-native-progress';
import { openDatabase } from 'react-native-sqlite-storage';
var db = openDatabase({ name: 'UserDatabase.db' });
let progressbardata = (id) => {
    var totalItems=0;
    db.transaction((tx) => {
      tx.executeSql('SELECT * FROM student where id = ?',[id],(tx,results) => {
          totalItems = results.rows.item(0).percent;
          return (totalItems);
      })
    })
}
const _renderContent = (item,index) => {
return (
<View>
   <Progress.Bar color='#68FF33' progress={progressbardata(item.id)}/>
   </View>
)
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)