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?
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
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With