我在使用 sqlite 时遇到了一个小问题。我的页面是:-shelf_list -shelf_detail
在shelf_list 中,我在单独的表中创建了一个shelf 和shelf_detail 信息。
在shelf_detail 中,我读取条形码并保存它们。
当我返回shelf_list时,我想显示货架的条码,例如:
- 第一个货架 9 个条形码
我的问题是我可以显示货架名称(第一个货架)但无法显示有多少条码(9 个条码)
这就是我 getShelf 及其详细信息的方式:
const getShelfs = async () => {
try {
let shelfArray = [];
let shelfBarcodes = [];
setPieceOfShelf([]);
//const jsonValueShlefs = await AsyncStorage.getItem(strings.getShelfs);
//jsonValueShlefs !== null ? setShelfs(JSON.parse(jsonValueShlefs)) : null;
await db.transaction(async tx => {
//rafları çekiyoruz
tx.executeSql('SELECT * FROM Shelves', [], (tx1, results) => {
const len = results.rows.length; //raf sayısı
console.log('raf sayısı', shelves.length);
if (len > 0) {
//raf sayısı kadar for döngüsü ile rafları state'e ekleyeceğiz
for (let index = 0; index < results.rows.length; index++) {
//console.log(results.rows.item(index));
shelfArray.push(results.rows.item(index));
}
shelfArray.map(element => {
//console.log('raf', element);
tx.executeSql(
'SELECT * FROM ShelfDetail WHERE BarcodeID="' +
element.ID +
'"',
[],
(tx1, results) => {
console.log(
JSON.parse(results.rows.item(0).BarcodeArray).BarcodeArray
.length,
);
//raf içindeki barkod sayısını array'e ekliyoruz
if (results.rows.item(0)) {
shelfBarcodes.push(
JSON.parse(results.rows.item(0).BarcodeArray).BarcodeArray
.length,
);
} else {
shelfBarcodes.push(0);
}
},
);
});
//array'leri state'e kaydediyoruz
setPieceOfShelf(shelfBarcodes);
setShelves(shelfArray);
setKeyForList(keyForList + 1);
}
});
});
setIsLoading(false);
setKeyForList(keyForList + 1);
} catch (error) {
console.error(error);
}
};