0

This is for a phonegap angular app. I would have thought binding to the db query return, result.rows in my case would be possible but it seems like it is not. The only way I could get this to work was with the commented out code where I manually push the data into an array row by row. Is this the only way?

The actually error received by binding to .rows is: Error: Duplicates in a repeater are not allowed. Repeater: item in items key: undefined:undefined

The service:

// only portion of code shown
query: function (q) {
        var d = $q.defer();
        var db = this.getDb();

        db.transaction(function (t) {
            t.executeSql(q, [], function (tx, results) {
                d.resolve(results);
            }, function (err) {
                d.reject(err);
            });

        }, function (err) {
            d.reject(err);
        }
        );

        return d.promise;
     }

The controller is like this:

  Sql.query('select * from DEMO').then(function (data) {
                console.log(data);
                //$scope.items = [];

                //for (i = 0, l = data.rows.length; i < l; i++) {
                    //$scope.items.push(data.rows.item(i));
                //}

                $scope.items = data.rows;  // this errors out
                $scope.$safeApply();
            });

The repeater is just a simple:

<div ng-repeat='item in items'>{{item.id}} {{item.data}}</div>
lucuma
  • 18,247
  • 4
  • 66
  • 91

1 Answers1

0

Based on the error message it looks like you have more than one undefined item in the data.rows array.

Your working code uses data.rows.item(i) is that creating an new empty object instead of undefined? Try changing data.rows.item(i) to data.rows[i] in your working code does that break as well?

Assuming you are using angular 1.1.5 here are some options:


Note: For others having a similar type of error Angular generates a $$hashKey to objects when doing an ng-repeat. This error indicates the same object is in the array (with the same $$hashKey) and is not allowed in 1.1.5 (and later?).

See this blog post and google groups post for more info. Also this pull request looks related so I'm not sure if this behavior is intended going forward though it appears to have been fixed in the past.

Gloopy
  • 37,767
  • 15
  • 103
  • 71
  • The query I am running only has two columns and two rows of data, id and data, both of which have and display data. I will downgrade the version and report back if that fixes it. – lucuma Jun 08 '13 at 17:31
  • I just had a chance to test this and experienced similar problems with both 1.1.4 and 1.1.5.. Backing down to 1.0.7 fixed it for anyone else having hashkey issues. – lucuma Jun 19 '13 at 20:19