Angularjs 使用angular js向json添加新数据
你好,我正在使用angular js。我尝试从json中删除数据,但当我刷新页面时,json文件仍然没有更改。我删除的数据仍然存在 我打开了我的json 这是我删除数据的代码:Angularjs 使用angular js向json添加新数据,angularjs,json,Angularjs,Json,你好,我正在使用angular js。我尝试从json中删除数据,但当我刷新页面时,json文件仍然没有更改。我删除的数据仍然存在 我打开了我的json 这是我删除数据的代码: $scope.deleteItem =function(experience){ var index = $scope.experiences.indexOf(experience); alert("Deleting DATA: "+ index);
$scope.deleteItem =function(experience){
var index = $scope.experiences.indexOf(experience);
alert("Deleting DATA: "+ index);
$scope.experiences.splice(index,1);
};
我需要编写php代码还是什么?我想我可以用angularjs中的代码删除这个文件。我还是新来的,所以请告诉我。只能在服务器端使用服务器更改文件code@charlietfl哦,好的。因此,使用这段代码还不足以删除或更新json?不,不足以。您需要将数据发送到服务器并修改其中的存储版本$scope.experiences.splice,只需从UI中的$scope.experiences数组中删除该项即可。如果您想更新json,您应该更新服务器端json模型,最好创建一个服务或类似的东西,然后通过索引或id参数调用它以从“myjson.com”中删除项,然后如果删除函数成功运行,它将返回结果,之后您可以运行$scope.experiences.splice以更新视图
$scope.deleteItem =function(experience){
var index = $scope.experiences.indexOf(experience);
alert("Deleting DATA: "+ index);
$scope.experiences.splice(index,1);
};