使用Angular js更新ng-repeat中的数据
Update data in ng-repeat using Angular js
我有一个问题,更新数据到数据库。例如:在我的表中包含特定id的三行。因此,当编辑我通过ng-repeat显示内容时。
<<p> 视图/strong> <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>
<<p> CI控制器/strong> public function updatePurchaseDetails()
{
$po_id = $this->uri->segment(4);
$data = file_get_contents('php://input');
$this->model->update_purchase_data($data,$data['count']);
}
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);
}
}
如何在提交时将编辑过的数据更新到db
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控制器文件:
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');
});
}
});
JS服务文件:
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);
}
}
});
相关文章:
- AngularJS -- 创建自定义数据绑定和 ng-repeat
- 尝试使用 AngularJS ng-repeat 显示 JSON 数据不起作用
- 使用 ng-repeat解析不均匀数据/ json对象
- 使用ng repeat从两个不同的JSON文件中提取数据
- 使用ng repeat用数组中的数据填充表行
- 如何在Firebase中使用Angularjs ng-repeat检索嵌套数据
- 如何在使用 ng-repeat 显示表数据时放置条件新行
- ng-repeat / ng-bind 不会显示我的数据
- 使用 ng-repeat 生成模板的副本,每个副本都有不同的数据
- Ng-repeat以呈现具有键值对的数据
- 从数据库中获取数据,并在 AngularJS 中的 ng-repeat 中使用它
- 如何在AngularJS(ng-repeat)中获取选定的单选按钮数据
- 角度 - 在不使用 ng-repeat的情况下获取数据长度
- AngularJS “ng-repeat |滤波器:..“没有像我预期的那样工作(不显示任何数据)
- 在角度材料对话框数据输入/推送后更新ng-repeat
- AngularJS ng-repeat在新数据进入时不更新视图
- Angular - ng-repeat - 获取 1 个列表中的所有 json 子数据
- 将数据从 Node 发送到 Angular 以用于 ng-repeat 的正确方法
- 以 ng-repeat 显示来自 Firebase 的数据
- 如何使用数据 ng-repeat获取从 A 到 Z 的索引值