admin管理员组文章数量:1420973
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?
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?
Share Improve this question edited May 21, 2015 at 20:35 rayt asked May 21, 2015 at 19:49 raytrayt 1941 silver badge8 bronze badges 2- Hi. You should add a tag for SqlResultsetRowList to this question. Since not all the properties/methods aren't shared in base JavaScript, only someone who knows SqlResultsetRowList will be able to answer your question. – Kathy Commented May 21, 2015 at 20:05
- Also, why are you defining the variable "rows" as results.rows, then not using it when you define the variable "row"? You might also want to change the name of the "rows" variable to something that isn't the same as a method you're using. – Kathy Commented May 21, 2015 at 20:07
2 Answers
Reset to default 9So 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
});
Try this
$.each(rows, function(i, val) {
var row = results.rows.item[i];
console.log('index:' +i+ ' val:' +val);
});
本文标签: javascriptjQueryeach on SqlResultsetRowList in SafariiOSStack Overflow
版权声明:本文标题:javascript - jQuery - $.each on SqlResultsetRowList in SafariiOS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745322902a2653458.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论