【发布时间】:2018-01-31 04:51:36
【问题描述】:
我正在尝试将值作为数组存储在 AsyncStorage 中,但是当我尝试从数组中获取值时,值并没有保存在那里并且什么也得不到。任何帮助将不胜感激。提前谢谢你,这是我的代码:
let searchString = this.state.inputValue
AsyncStorage.getItem('searches', (res) => {
var searches
if (res === null) {
searches = []
}else {
searches = JSON.parse(res)
}
searches.push({
searchString: searchString
})
AsyncStorage.setItem('searches', JSON.stringify(searches), (res) => {
console.log('====FirstPage====setItem==async==='+res)
})
});
//从异步存储中获取值:
AsyncStorage.getItem('searches', (res) => {console.log('===res==='+res)})
【问题讨论】:
-
你能显示在 AsyncStorage 中保存/存储值的代码吗?
-
你使用了 AsyncStorage.getItem() 吗?
-
我已经更新了我的问题。
标签: arrays react-native asyncstorage