多种形式 ng-repeat - 仅回发当前 $scope,而不是整个对象

multiple forms ng-repeat - posting back the current $scope only, not whole object

我有多个使用 ng-repeat 的表单。

<div ng-repeat="individual in orderDetails track by $index">
    <form ng-submit="saveDetails();">
      <input ng-model="individual.order.statusText">
      <button type="submit">Save changes</button>
    </form>
</div>

这是我的对象中存储的内容的示例,对于 OrderDetails.[=14= 中的每个 individual(IE - 对象) ]

orderDetails {
    object{
        foo {},
        bar {},
        order {}
    },
    object{
        foo {},
        bar {},
        order {}
    }       
}

现在我在我的转发器中引用了个人的数据,我怎么能只提交来自单个个人的订单呢?发回服务器,而不是整个 orderDetails 对象?

这是我的保存功能,用于表单提交按钮

$scope.saveDetails = function(data, status) {               

    ordersService.updateOrder($scope.orderDetails.individual.order)

    // once submitted update the whole model on the page again
    .success(function(data, status) {                   
        $scope.orderDetails = data;                 
    })                         
}

这是我的服务:

getData.updateOrder = function(data){
    var url = '/service/rest/orders';

    return $http.post(url, data)                    

    .error(function (data, status, headers, config) {
        console.error('Error fetching feed:', status, headers, config);
    });
};            

return getData; 

再次感谢您的帮助。

简单,将individual对象传入提交处理器,例如

$scope.saveDetails = function(individual) {
    ordersService.updateOrder(individual.order).success(function(data) {
        $scope.orderDetails = data;
    });
};

在你的 HTML

<form ng-submit="saveDetails(individual)">

要用新数据覆盖 individual 顺序,您只需将其写回 individual,例如

.success(function(data) {
    angular.extend(individual, data); // or angular.merge for deep extending
});