【发布时间】:2020-12-09 16:51:14
【问题描述】:
我正在构建一个应用程序,用户在其中插入任务和创建任务的时间,并且两者都保存在 react native 中的 asyncStorage 中。当将新任务添加到异步存储时,我希望 getItems() 函数同时显示上一个任务和新任务。
怎么办?
async function saveItems() {
const items = []
items.push(task,timestamp )
await AsyncStorage.setItem('key', JSON.stringify(items))
}
async function getItems() {
try {
const items = await AsyncStorage.getItem('key');
if (items !== null) {
console.log(JSON.parse(items));
}
} catch (error) {
console.log(error)
}
}
【问题讨论】: