Cannot save/push array of objects to parse backend

时间:2015-07-28 23:16:47

标签: arrays angularjs parse-platform

I was attempting to add an array to the parse.com backend. I created an array:

  var addHoles = function () {
    $scope.holeArray = [];
    for (var i = 0; i < 18; i++) {
        $scope.holeArray[i] = {
            number: i + 1,
            par: '',
            distance: '',
            handicap: ''
        };
    }
    console.log($scope.holeArray);
    return $scope.holeArray;
};

and then used ng-repeat to display the array and ng-model to allow the user to change the array.

      <div ng-repeat="hole in holeArray" class="row">
                        <div class="form-group">
                            <div class="col-md-2">
                                <div class="form-group form-md-line-input">
                                    <input type="text" class="form-control" id="form_control_1" ng-model="hole.number" readonly>
                                    <label for="form_control_1">Hole Number</label>
                                </div>
                            </div>

I was getting an unusual error from parse. and could not get parse to save the array.

1 个答案:

答案 0 :(得分:1)

It turns out the issue was that when you use ng-repeat angularjs adds a $$hashKey. This $$hasKey conflicts with parse's backend formatting requirements. So, to fix the issue all I had to do was use "track by" in my ng-repeat.

<div ng-repeat="hole in holeArray track by hole.number" class="row">

This took me hours to figure out. Hopefully it saves someone else time and headache.