2016-08-11 19 views
7

Tôi gặp sự cố khi cập nhật dữ liệu lên cơ sở dữ liệu. Ví dụ: trong bảng của tôi chứa ba hàng cho một id cụ thể. Vì vậy, trong khi chỉnh sửa đang hiển thị nội dung thông qua ng-lặp lại.Cập nhật dữ liệu trong ng-repeat bằng Angular js

xem

<tr class="odd gradeX" ng-repeat="d in data"> 
     <td> <input type="text" name="tools" class="form-control" ng-model="d.po_tools" placeholder="Tools"> </td> 

     <td> <input type="text" name="qnty" class="form-control" ng-model="d.po_quantity" placeholder="Quantity"> </td> 
    </tr> 

khiển CI

public function updatePurchaseDetails() 
{ 
    $po_id = $this->uri->segment(4); 
    $data = file_get_contents('php://input'); 
     $this->model->update_purchase_data($data,$data['count']); 

} 

mô hình

public function update_purchase_data($data,$count) 
    { 
     $count=$count+1; 
     for($i=0;$i<$count;$i++) 
     { 
      $data_array = array(

      'po_id' => $id, 
      'po_tools' => $data['data']['po_tools'] , 
      'po_quantity' =>$data['data']['po_quantity'] 
      ); 
      $this->db->update('purchase_order_tool', $data_array);  
      $this->db->where('po_id',$purchase_id); 
     } 
    }  

Làm thế nào để cập nhật dữ liệu chỉnh sửa để db khi gửi.

+1

Có thể bạn sẽ cần phải thêm nhiều mã của mình. Bạn đang sử dụng một biểu mẫu? Làm thế nào bạn gửi dữ liệu đến máy chủ? – pcnate

+0

có vẻ như điều này sẽ ở dạng, và sẽ cần một hành động gửi kèm theo nó để bạn có thể đăng lên cơ sở dữ liệu của mình nếu bạn thực sự muốn lưu thông tin ở đó – HolyMoly

+0

bằng cách sử dụng ng-click..then $ http.post (base_url + "purchase/tools/updatePurchaseDetails /" + purchase_id, {data: $ scope.data, count: $ scope.counter}). – robins

Trả lời

0

HTML:

<td> <input type="text" name="tools" class="form-control" ng-model="d.po_tools" ng-keyup="submit('tools');" value="{{d.po_tools}}" placeholder="Tools"></td> 

    <td> <input type="text" name="qnty" class="form-control" ng-model="d.po_quantity" ng-keyup="submit('quantity');" value="{{d.po_quantity}}" placeholder="Quantity"> </td> 

JS điều khiển file:

angular.module('appname').controller('myCtrl',function($scope,Service){ 

    if(!$scope.d) $scope.d = {}; 

    $scope.submit = function (type){ 
    var obj = { 
     data : $scope.d, 
     type : type 
    } 
    service.send(obj).then(function(success){ 
     console.log(success); 
    },function(err){ 
     console.log(err); 
    }).finally(function(){ 
     console.log('finish'); 
    }); 
    } 

}); 
Dịch vụ JS

file:

angular.module('appname').factory('Service',$http,function(){ 
    return { 
    send : function(obj){ 
     var params = $.param(obj); 
     var options = { 
      url : 'http://example.com/upload.php', 
      method: 'POST', 
      data : params, 
      headers: { 
       'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' 
      } 
      }; 
     return $http(options); 
    } 
    } 
}); 
Các vấn đề liên quan