Ner*_*Jok 8 javascript android react-native asyncstorage
我正在考虑如何在编写的文档中使用React-native AsyncStorage multiGet:
AsyncStorage.multiGet(keys, (err, stores) => {
Run Code Online (Sandbox Code Playgroud)
但这些键应该如何正常?以下是它们在我的应用程序中的设置方式:
AsyncStorage.multiSet([['@BarcodeList', JSON.stringify(scanedList)], ['@ScannedBarcode', gotCode]]);
Run Code Online (Sandbox Code Playgroud)
没关系,但是如何使用multiGet检索数据呢?使用getItem似乎工作,我做错了什么?下面两个(getItem,multiGet).
AsyncStorage.multiGet(["@BarcodeList", "@ScannedBarcode"]).then((scanedList2, scannedBarcode) => {
//AsyncStorage.getItem("@BarcodeList").then((scanedList2) => {
Run Code Online (Sandbox Code Playgroud)
Pri*_*dya 19
它按以下方式工作,因为它提供嵌套数组响应
该数组包含键作为index 0和值作为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
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5157 次 |
| 最近记录: |