Phonegap IndexedDb不会在较大的数据库上提交Windows Phone 10中的数据

时间:2016-08-05 15:13:41

标签: cordova indexeddb windows-10-mobile

我有一个phonegap应用程序,它从(CORS)Web服务中提取数据并将其本地存储在IndexedDB中。

这一切在Android,iOS(使用shimm)和Windows Phone 8.1上运行正常,但在Windows Phone 10上如果数据集很大则无法完成事务,目前有2个特定表失败,有些表有一些276条记录的项目(json对象的总大小为350KB)和一条包含16条记录的base64照片数据(json对象大小刚刚超过4MB),这个数据并不大。

以下代码将数据保存到数据库中:

getDataSingleTable: function (table, callback) {
    // get data for a single table
    if (!table) {
        // table name from array
        table = json_xfer.getTableList[json_xfer.currentGetTable];
    }

    var numRecords = 0;
    var anchor = '#li_get_' + table;
    var txt = $(anchor).html();
    $(anchor).html(txt + ' fetching...');

    // get data from CORS call
    json_xfer.corsGetdata(table, function (data) {
        // data is an array of json objects
        numRecords = data.length;
        console.log('fetched ' + table + ' ' + numRecords + ' row(s)');

        var trn = app.db.transaction([table], 'readwrite');
        var doDelete = xfer.latestUpds.length === 0;
        var obs = trn.objectStore(table);

        $(anchor).html(txt + ' applying ' + numRecords + ' row(s)...');
        var numSaved = 0;


        json_xfer.deleteLocalData(obs, doDelete, function () {
            if (numRecords === 0) {
                // in iOS if there's no records then trn.oncomplete will not be fired so
                // the code from that is now moved to another function we can call from here
                json_xfer.gotDataSingleTable(anchor, txt, numRecords);
            } else {
                // loop data
                data.forEach(function (row) {
                    // save data
                    var req = obs.put(row);
                    req.onerror = onIDBError;
                    req.onsuccess = function (event) {
                        numSaved++;
                        console.log('saved record ' + table + ' ' + row.id + ' ' + numSaved + '/' + numRecords);
                    };
                });
            }
        });

        trn.oncomplete = function () {
            console.log('trn.oncomplete(' + table + ')');
            if (callback) {
                callback();
            } else {
                if (numRecords > 0) {
                    json_xfer.gotDataSingleTable(anchor, txt, numRecords);
                }
            }

        };
        trnWrite.onabort = function() {
            console.log('transaction aborted');
        };
    });


},

这几乎是这样做的: 从CORS Web服务获取数据(返回JSON数组) 清除dataStore 循环JSON数组并保存到dataStore

在Windows 10中,它到达最后一个console.log(已保存的记录照片5b9200e3-4b33-4f4f-k0r3-2172139d36c3 16/16),但trn.oncomplete永远不会被触发。 transaction.onAbort确实被触发

这似乎是一个大小问题,一旦数据库增长到一定的大小(大约2到4MB),任何对数据库的保存都会失败。

对外部函数的调用应该通过名称自我解释。

1 个答案:

答案 0 :(得分:0)

解决方案是使用" windows"平台而不是" wp8"