使用ng-submit get error Cannot read 属性 'name' of undefined提交数组数据

Submit array data with ng-submit get error Cannot read property 'name' of undefined

我想提交一个包含数组数据的表单

<form ng-submit="processForm()">
     <div class="item item-text-wrap item-toggle" ng-repeat="item in items | orderBy: ['id','name']">
         {{item.name}}
         <label class="toggle toggle-calm">
              <input type="checkbox" ng-model="formData[$index].id" ng-true-value="{{item.id}}" />
             <div class="track">
                <div class="handle"></div>
             </div>
         </label>
     </div>
     <div class="item">
        <button class="button button-block button-calm">Submit</button>                
     </div>
</form>

在控制器中:

.controller('ProcessCtrl', function ($scope, $http, $localStorage, $state) {
        $scope.formData = [];
        $scope.processForm = function () {
            $http({
                method: 'post',
                url: 'process.php',
                data: $.param($scope.formData),
                headers: {'Content-Type': 'application/x-www-form-urlencoded'}
            })
            .success(function (result) {
                 console.log(result);
            })
        }
    })

提交时出现此错误 Cannot read property 'name' of undefined。任何人都可以指出代码有什么问题吗?

您尝试过让您的 $scope.formData 成为对象吗?

例子

 $scope.formData = {};