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);
  }
  } 
  );
}

 

posted @ 2019-02-13 12:10  菩提树下的丁春秋  阅读(751)  评论(0编辑  收藏  举报