angularJs实现修改功能
思路: 对表单中内容进行修改,首先需要获取这个内容,再进行修改,再清空弹窗中的内容
//查询实体 $scope.findOne=function(id){ $http.get('../brand/findOne.do?id='+id).success( function(response){ $scope.entity= response; } ); }
第一步获取相应实体'
<button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" ng-click="findOne(entity.id)" >修改</button>
第二步保存数据:
$scope.save=function(){ var methodName='add';//方法名称 if($scope.entity.id!=null){//如果有 ID methodName='update';//则执行修改方法 } $http.post('../brand/'+ methodName +'.do',$scope.entity ).success( function(response){ if(response.success){ //重新查询 $scope.reloadList();//重新加载 }else{ alert(response.message); } } ); }
本文详细介绍了使用AngularJS实现修改功能的具体步骤。首先通过按钮触发findOne方法获取要修改的实体,然后在弹窗中显示实体内容供用户修改,最后通过save方法保存修改后的数据。save方法会判断实体是否有ID,从而决定调用add还是update方法。
170

被折叠的 条评论
为什么被折叠?



