本文介绍了如何使用React Native中的AsyncStorage multiGet检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm considering how to use React-native AsyncStorage multiGet in docs written:

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

但这些键应该如何正确看起来像?这是他们的表现在我的应用程序中设置:

But how those keys should properly look like? Here is how they are set within my application:

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

没关系,但我怎样才能检索到这些数据multiGet?使用getItem似乎有效,我做错了吗?两者(getItem,multiGet)都在下面。

It's ok, but how can i retrieve that data with multiGet? With getItem it seems working, what i am doing wrong? both(getItem, multiGet) of them below.

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


推荐答案

它按以下方式工作,因为它给出嵌套数组响应

It works the following way, since it gives nested array response

数组包含 key as index 0 和 value as index 1

The array contains key as index 0 and value as 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
        })

这篇关于如何使用React Native中的AsyncStorage multiGet检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:02