Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - $.each on SqlResultsetRowList in Safari/iOS

I'm trying to use $.each to speed up iteration of a SqlResultsetRowList where I'm currently using a For loop. Here is the new code -

localDB.transaction(function(transaction){ transaction.executeSql(query, [val], function(transaction, results) { var rows = results.rows; $.each(rows, function(i) { var row = results.rows.item(i); }); } ) });

The problem is i is being returned as not the index but the string "length" and it obviously breaks at that point.

I've done some further testing and this works as expected in Chrome. Chrome sees the SqlResultsetRowList as an array but Safari doesn't. Is it possible to maybe convert the result set to an array so Safari can iterate it using $.each?

like image 949
rayt Avatar asked Jan 09 '23 08:01

rayt


1 Answers

So again this seems to only affect Safari and Mobile Safari and I have found the following to suffice for what I was looking to do. Adding for anyone possibly in the same situation.

Since Safari doesn't see a SqlResultsetRowList as an array you need to create one from it.

var contacts = [];

for (i = 0; i < results.rows.length; i++){
    contacts.push(results.rows.item(i));
}

Now that you have the array created from the results you can iterate contacts using $.each.

$.each(contacts, function() {
    var ID = this.Contact_ID;
    //more logic here
});
like image 57
rayt Avatar answered Jan 18 '23 17:01

rayt