如何在本机反应中从 asyncStorage 中删除单个项目?

鲑鱼

我有一个用 asyncStorage 存储的项目列表,它们都有相同的键,使用await AsyncStorage.removeItem(key);它删除整个项目列表的功能有没有办法只删除一个项目。

async removeItemValue(key) {

  try {
    await AsyncStorage.removeItem(key);
    return true;
  }
  catch(exception) {
    return false;
  }
回击

我将要做的:

  1. 获取列表
  2. 删除项目
  3. 保存新列表。

就像是:

const value = await AsyncStorage.getItem(theKey);
if (value !== null){
     var index = array.indexOf(theItem);
     if (index > -1){
         value.splice(index, 1);
     }
}
AsyncStorage.setItem(theKey, value);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章