作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在考虑如何在编写的文档中使用 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 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
})
关于javascript - 如何在 React Native 中使用 AsyncStorage multiGet 检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50133440/
我是一名优秀的程序员,十分优秀!