如何在 React Native 中使用 AsyncStorage multiGet 检索数据
How to retrieve data with AsyncStorage multiGet in React Native
我正在考虑如何在编写的文档中使用 React-native AsyncStorage multiGet:
AsyncStorage.multiGet(keys, (err, stores) => {
但是这些键应该是什么样子的呢?以下是它们在我的应用程序中的设置方式:
AsyncStorage.multiSet([['@BarcodeList', JSON.stringify(scanedList)], ['@ScannedBarcode', gotCode]]);
没关系,但我如何使用 multiGet 检索该数据?使用 getItem 似乎有效,我做错了什么?下面的两者(getItem,multiGet)。
AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then((scanedList2, scannedBarcode) => {
//AsyncStorage.getItem("@BarcodeList").then((scanedList2) => {
它的工作方式如下,因为它给出了嵌套数组响应
数组包含 key 作为 index 0
和 value 作为 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:
AsyncStorage.multiGet(keys, (err, stores) => {
但是这些键应该是什么样子的呢?以下是它们在我的应用程序中的设置方式:
AsyncStorage.multiSet([['@BarcodeList', JSON.stringify(scanedList)], ['@ScannedBarcode', gotCode]]);
没关系,但我如何使用 multiGet 检索该数据?使用 getItem 似乎有效,我做错了什么?下面的两者(getItem,multiGet)。
AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then((scanedList2, scannedBarcode) => {
//AsyncStorage.getItem("@BarcodeList").then((scanedList2) => {
它的工作方式如下,因为它给出了嵌套数组响应
数组包含 key 作为 index 0
和 value 作为 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
})