簡體   English   中英

HTML5本地數據庫回調

[英]HTML5 Local Database Callback

我要在本地數據庫中插入數百行。

插入之后,我想從該表中選擇*以獲取並顯示所有這些記錄。

我嘗試將Select語句放入INSERT事務的回調中,但無法正常工作。 在執行頁面刷新時,我測試了SELECT語句,以查看它是否有效。

有人可以幫忙嗎? 插入所有記錄后,我希望能夠在不刷新頁面的情況下全部選擇它們。 謝謝!

database.db.transaction(function(tx){JSON處理

                tx.executeSql('INSERT INTO ...'),
                    [DATA IS HERE],

                    function (tx, callback) {
                        alert(callback.message);

                        database.db.transaction(function (tx) {
                        tx.executeSql('SELECT * from table;', [], tableSelectHandler, errorHandler);
                                        });
                                    },
                    function (tx, error) {
                         alert(error.message);
                    }

            });

回答這個特定問題有點晚了,但是可以幫助別人,所以...

db.transaction函數還具有用於Error和Success的回調函數。 您可以將SELECT代碼放在Success回調中,並在所有插入操作執行后在事務結束時執行。 基本上,您應該具有以下內容:

database.db.transaction(function (tx) { //JSON PROCESSING

    tx.executeSql('INSERT INTO ...'),
        [DATA IS HERE],
    function (tx, callback) {
        alert("Insert ok");
    },
    function (tx, error) {
        alert("Error inserting: " + error.message);
    }
},
function (error) { // This is the Error callback of the TRANSACTION
     alert(error.message);
},
function (result) { // This is the Success callback of the TRANSACTION
    alert("TRANSACTION completed");

    database.db.transaction(function (tx) {
        tx.executeSql('SELECT * from table;', [], tableSelectHandler, errorHandler);
    }); // Your tableSelectHandler should take care of the result of the Select
});

希望能幫助到你。 干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM