gpt4 book ai didi

javascript - 如何在 React Native 中使用 AsyncStorage multiGet 检索数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:52:55 27 4
gpt4 key购买 nike

我正在考虑如何在编写的文档中使用 React-native AsyncStorage multiGet:

AsyncStorage.multiGet(keys, (err, stores) => {

但是这些键应该是什么样子的呢?以下是它们在我的应用程序中的设置方式:

AsyncStorage.multiSet([['@BarcodeList', JSON.stringify(scanedList)], ['@ScannedBarcode', gotCode]]);

没关系,但我如何使用 multiGet 检索该数据?使用 getItem 似乎有效,我做错了什么?它们的 both(getItem, multiGet) 在下面。

AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then((scanedList2, scannedBarcode) => {
//AsyncStorage.getItem("@BarcodeList").then((scanedList2) => {

最佳答案

它的工作方式如下,因为它给出了嵌套数组响应

数组包含 key 作为 index 0value 作为 index 1

 AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then(response => {
console.log(response[0][0]) // Key1
console.log(response[0][1]) // Value1
console.log(response[1][0]) // Key2
console.log(response[1][1]) // Value2
})

关于javascript - 如何在 React Native 中使用 AsyncStorage multiGet 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50133440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com