javascript 使用javascript从web sql中的结果集中删除行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12676426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 16:50:08  来源:igfitidea点击:

delete row from result set in web sql with javascript

javascripthtmlweb-sql

提问by Kaijin

I understand that the result set from web sql isn't quite an array, more of an object? I'm cycling through a result set and to speed things up I'd like to remove a row once it's been found. I've tried "delete" and "splice", the former does nothing and the latter throws an error. Here's a piece of what I'm trying to do, notice the delete on line 18:

我知道来自 web sql 的结果集不是一个数组,更像是一个对象?我正在循环查看结果集,为了加快速度,我想在找到一行后将其删除。我试过“删除”和“拼接”,前者什么都不做,后者抛出一个错误。这是我正在尝试做的一部分,注意第 18 行的删除:

function selectFromReverse(reverseRay,suggRay){
    var reverseString = reverseRay.toString();
    db.transaction(function (tx) {  
        tx.executeSql('SELECT votecount, comboid FROM counterCombos WHERE comboid IN ('+reverseString+') AND votecount>0', [], function(tx, results){
            processSelectFromReverse(results,suggRay);
        }); 
    }, function(){onError});
}

function processSelectFromReverse(results,suggRay){
    var i = suggRay.length;
    while(i--){
        var j = results.rows.length;
        while(j--){
            console.log('searching');
            var found = 0;
            if(suggRay[i].reverse == results.rows.item(j).comboid){
                delete results.rows.item(j);
                console.log('found');
                found++;
                break;
            }
        }       
        if(found == 0){
            console.log('lost');
        }
    }
}

回答by Kyaw Tun

Actually you use DELETE sql command to delete the record from the database. For example:

实际上您使用 DELETE sql 命令从数据库中删除记录。例如:

tx.executeSql('DELETE FROM counterCombos WHERE comboid = ?', [comboid], success, error);

processSelectFromReversecould modified to include txas input like

processSelectFromReverse可以修改为包括tx作为输入

processSelectFromReverse(results,suggRay,tx) 

回答by Ryan

Web SQL has been dropped from the HTML5 workupfor almost 2 years now and isn't supported. Web Storageand Indexed DBhave taken its place.

Web SQL 已从 HTML5 工作中删除近 2 年,并且不受支持。Web StorageIndexed DB已经取而代之。

Your syntax for deleting objects: delete object;is correct. It's not used often in JavaScript but I have used it and that is the correct usage.

您删除对象的语法:delete object;是正确的。它在 JavaScript 中并不经常使用,但我已经使用过它,这是正确的用法。

Using web-storage (more commonly called local storage) you would instansiate a localStorageobject which comes with the method removeItem(item key), already built in.

使用网络存储(通常称为本地存储),您可以实例化一个localStorage对象,该对象removeItem(item key)已经内置。

You can see more at the above link on webstorage or go here for a tutorial.

您可以在上面的 webstorage 链接中查看更多信息,或者到这里查看教程

回答by arielf

If your concern is IOS or Android, making an application that is wrapped natively would allow you to create a javascript interface. From this interface you can access (for android) sqlite and create a nice, query0able solution. The downside is this would require people downloading your application rather then accessing a site.

如果您关心的是 IOS 或 Android,那么制作一个原生包装的应用程序将允许您创建一个 javascript 界面。从这个界面你可以访问(对于安卓)sqlite 并创建一个很好的、可查询的解决方案。缺点是这需要人们下载您的应用程序而不是访问站点。

http://caniuse.com/indexeddb

http://caniuse.com/indexeddb

indexeddb support is growing rather slowly. With a proper coding style you could probably use local storage (as mentioned in the above comments) with pretty respectable speeds.

indexeddb 支持增长相当缓慢。通过适当的编码风格,您可能可以以相当可观的速度使用本地存储(如上述评论中所述)。