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

标签 javascript android react-native asyncstorage

我正在考虑如何在编写的文档中使用 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/

相关文章:

javascript - 如何在 Jasmine 中测试函数表达式

android - 如何在mysql数据库中每10秒更新一次经度和纬度?

node.js - [未处理的 promise 拒绝: SyntaxError: Unexpected token i in JSON at position 7]

android - React-native-fcm 不推送关闭应用程序的通知

javascript - 如何刷新页面以便我的表不会继续添加到现有表中?

c# - 如何将数据从 C# 传递到 jquery/javascript?

android - 如何从传感器确定设备方向

javascript - 无法清除 react native 应用程序中的setInterval

javascript - Collection_select 在 javascript 的帮助下使用参数重定向

java线程调用耗时的native方法时被阻塞