Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 多个表单ng重复-仅回发当前$scope,而不是整个对象_Angularjs_Angularjs Scope_Angularjs Ng Repeat_Angular Ngmodel - Fatal编程技术网

Angularjs 多个表单ng重复-仅回发当前$scope,而不是整个对象

Angularjs 多个表单ng重复-仅回发当前$scope,而不是整个对象,angularjs,angularjs-scope,angularjs-ng-repeat,angular-ngmodel,Angularjs,Angularjs Scope,Angularjs Ng Repeat,Angular Ngmodel,我有多个使用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>

我有多个使用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>
现在,我在中继器中使用个人引用数据,如何在发回服务器时仅提交单个个人的订单,而不是整个订单详细信息对象

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

$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; 

再次感谢您的帮助。

简单,将
个体
对象传递到提交处理程序中,例如

$scope.saveDetails = function(individual) {
    ordersService.updateOrder(individual.order).success(function(data) {
        $scope.orderDetails = data;
    });
};
在你的HTML中

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

问题不是很清楚。。。只要告诉我们html是什么样子和相关的代码。。。它工作的背景在这个问题上真的相关吗?可能是在@entre用最少的代码道歉来创建一个plunker,这很难解释。我根据你的建议改进了我的问题,这更有意义吗?谢谢你的回复。非常感谢@phil,现在正在提交!这也是一个简单的解决方案。您知道如何将数据加载回作用域吗?“$scope.orderDetails”包含所有订单,而数据仅包含单个订单。它打破了目前成功的模式。再次感谢。事实上,我解决了这个问题,没有使用“$scope.orderDetails=data;”,而是使用了“$scope.orderDetails.push(data);”。干杯@德斯蒙德,我还添加了另一个way@Desmond不客气。如果您正在进行单元测试,您会发现将所需参数传递到范围函数中更容易编写测试。谢谢@Phil,很高兴知道这一点。我仍然是一个有棱角的新手,我会努力了解单元测试,我会确保做到这一点。
<form ng-submit="saveDetails(individual)">
.success(function(data) {
    angular.extend(individual, data); // or angular.merge for deep extending
});