这是我的HTML:
<tr ng-repeat="student in students track by $index">
//some code here
<button ng-click="remove(student)">Delete</button>
</td>
</tr>
这是我的.js文件代码,用于删除学生(不是从本地存储中删除):
$scope.remove = function(student) {
var index = $scope.students.indexOf(student);
$scope.students.splice(index, 1);
}
如何从我的js代码访问本地存储,以及如何从本地存储中删除特定的学生。
听起来您应该将问题改写为“如何从js代码访问浏览器的本地存储?”
您可以使用js代码访问localStoragelocalStorage
。我将从中删除您的学生,$scope.students
完成后,将新数组设置为本地存储中的一项:
$scope.remove = function(student) {
var index = $scope.students.indexOf(student);
$scope.students.splice(index, 1);
localStorage.setItem('students', JSON.stringify($scope.students));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句