Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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_Angularjs_Local Storage - Fatal编程技术网

Javascript 向localstorage添加值,而不是替换它

Javascript 向localstorage添加值,而不是替换它,javascript,angularjs,local-storage,Javascript,Angularjs,Local Storage,我希望将ngStorage的值添加到locastorage AdddMatch。而在我的代码中,当我刷新页面时,它会替换已经存在的值 $scope.addIdMatch = function(infoMatchHomeTeam, infoMatchGoalHomeTeam, infoMatchGoalAwayTeam, infoMatchAwayTeam) { $i = $i +1 $localStorage[$i] = { infoMatchHomeTeam, i

我希望将ngStorage的值添加到locastorage AdddMatch。而在我的代码中,当我刷新页面时,它会替换已经存在的值

 $scope.addIdMatch = function(infoMatchHomeTeam, infoMatchGoalHomeTeam, infoMatchGoalAwayTeam, infoMatchAwayTeam) {
    $i = $i +1
    $localStorage[$i] = {
      infoMatchHomeTeam, infoMatchGoalHomeTeam, infoMatchGoalAwayTeam, infoMatchAwayTeam
    }
  };

$i
在哪里初始化?很可能,重新加载时从
0
开始,而不是从
$localStorage
中已有的项目长度开始。噢,谢谢,我将$I=$I+1替换为$I=localStorage.length+1,
$I
在哪里初始化?很可能,重新加载时从
0
开始,而不是从
$localStorage
中已有的项目长度开始。噢,谢谢,我将$I=$I+1替换为$I=localStorage.length+1