Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 正在从localStorage中的数组中删除项_Javascript_Angular - Fatal编程技术网

Javascript 正在从localStorage中的数组中删除项

Javascript 正在从localStorage中的数组中删除项,javascript,angular,Javascript,Angular,我已经尝试这么做了一段时间了,下面的代码是我目前拥有的,当我只有一个数组时它就可以工作,但是当我运行删除功能时,整个应用程序冻结,我无法退出,有人能告诉我我做错了什么吗。我对输入的每个数组都有自动输入ID,但我不知道为什么它会冻结 /*收藏夹服务*/ 公共deleteLocalStorage(id,i):无效{ const currentary=this.storage.get(this.storage\u键); 对于(i=0;i

我已经尝试这么做了一段时间了,下面的代码是我目前拥有的,当我只有一个数组时它就可以工作,但是当我运行删除功能时,整个应用程序冻结,我无法退出,有人能告诉我我做错了什么吗。我对输入的每个数组都有自动输入ID,但我不知道为什么它会冻结

/*收藏夹服务*/
公共deleteLocalStorage(id,i):无效{
const currentary=this.storage.get(this.storage\u键);
对于(i=0;i

与其在localstorage中存储数组,不如在存储时对数组进行字符串化,并在获取时对其进行解析。这样,您就不会在localstorage中存储复杂的数组,而是一个字符串


public deleteLocalStorage(id, i ): void {
  const currentArray = JSON.parse(this.storage.get(this.STORAGE_KEY));
  for (i = 0; i < currentArray.length; ++i) {
    if (currentArray[i].id === id) { currentArray.splice(i, 1); }
  }
  // insert updated array to local storage
  this.storage.set(this.STORAGE_KEY, JSON.stringify(currentArray));
}


localStorage.set(key, JSON.stringify(arr));

let x = JSON.parse(localStorage.get(key));

公共deleteLocalStorage(id,i):无效{
const currentary=JSON.parse(this.storage.get(this.storage_KEY));
对于(i=0;i
与其在localstorage中存储数组,不如在存储时对数组进行字符串化,并在获取时对其进行解析。这样,您就不会在localstorage中存储复杂的数组,而是一个字符串


public deleteLocalStorage(id, i ): void {
  const currentArray = JSON.parse(this.storage.get(this.STORAGE_KEY));
  for (i = 0; i < currentArray.length; ++i) {
    if (currentArray[i].id === id) { currentArray.splice(i, 1); }
  }
  // insert updated array to local storage
  this.storage.set(this.STORAGE_KEY, JSON.stringify(currentArray));
}


localStorage.set(key, JSON.stringify(arr));

let x = JSON.parse(localStorage.get(key));

公共deleteLocalStorage(id,i):无效{
const currentary=JSON.parse(this.storage.get(this.storage_KEY));
对于(i=0;i
通常不能直接使用localStorage存储阵列。但是angular local storage支持它,我想知道你是否在使用浏览器本地存储?如果你看了这篇文章,那就太好了,如果你在使用浏览器的本地存储,你需要对它进行字符串化:通常你不能直接用本地存储存储阵列。但是angular local storage支持它,我想知道你是否在使用浏览器本地存储?如果你看这篇文章会很好,如果你在使用浏览器本地存储,你需要对它进行字符串化:我已经尝试过这种方式,当我尝试删除arrayYour循环是一个无限循环时,应用程序仍然会冻结,您没有增量。将您的循环更新为以下
for(让i=0;i
我已经尝试过这种方法,并且当我尝试删除一个数组时,应用程序仍然冻结。您的循环是无限循环,您没有增量。将循环更新为以下
for(让i=0;i