【发布时间】:2018-01-16 17:58:45
【问题描述】:
目前,我正在使用 AsyncStorage.setItem() 将带有字符串化 JSON 对象的字符串键推送到 AsyncStorage。 IE:
当我使用 getAllKeys() 和 multiGet() 检索 AsyncStorage 中的所有内容时,我意识到我只想访问对象本身而没有使用密钥。
我只访问字符串化对象的最有效方法是什么?我当前的函数,其中 element 表示键和值:
importData = () => {
AsyncStorage.getAllKeys().then(keys => AsyncStorage.multiGet(keys)
.then((result) => {
result.map(req => req.forEach((element) => {
this.setState({ favorites: JSON.parse(element) });
console.log(this.state.favorites);
}));
}));
}
【问题讨论】:
标签: javascript json react-native foreach asyncstorage