我正在努力与Phonegap/Cordova的错误。我建立和连接设备中测试我的应用程序,这是我得到的错误:使用webSQL(SQLite)phonegap代码有问题的承诺
INVALID_STATE_ERR:DOM异常11
无我发现作品的解决方案。他们中的大多数都旨在使用ajax,而这里并不是这种情况。我发现了另一个关于phonegap的问题,他们说这可能是因为该设备还没有准备好,但我已经检查过我的设备。
这是在错误被抛出(我使用的是无极填充工具BTW,因为它不是在科尔多瓦支持到目前为止)的代码:我怀疑它可能有一些做
/**
* Clients insertion
* @param tx
* @param clientes
* @return {Promise}
*/
clientes = function(clientes) {
return new Promise(function(resolve, reject) {
var clientesCount = clientes.length;
if (clientesCont === 0){
resolve();
}
else {
APP.db.transaction(function(tx) {
$.each(clientes, function(i, cliente) {
var idclienteLocal;
// Current client
tx.executeSql("INSERT OR REPLACE INTO clientes (id, name, ...) " +
"VALUES " +
"(?,?,...)",
[cliente.id, cliente.name],
function(tx, res) {
clientesCount--;
idclienteLocal = res.insertId;
// Clien phones
telefonosCliente(tx, cliente, idclienteLocal).then(function() {
// Client credits
creditosCliente(tx, cliente, idclienteLocal).then(function() {
if (clientesCount === 0) {
resolve();
}
}).catch(function(error) {
reject('Error créditos cliente ' + cliente.empresa + ': ' + error);
});
}).catch(function(error) {
reject('Error teléfonos cliente ' + cliente.empresa + ': ' + error);
});
}, function(tx, error) {
reject(error.message);
});
});
});
}
});
}
循环(我为此使用jQuery),所以我尝试使用递归函数对前一个迭代进行排序,但它甚至不能在浏览器中工作(第一个处理器中的PromiseClient ()调用,在clientes()内不会解决)。这里是修改后的代码:
/**
* Recursive function to process each client one after the other
* @param tx
* @param clientes
* @param cliente
* @return {Promise}
*/
procesarCliente = function(tx, clientes, cliente) {
return new Promise(function(resolve, reject) {
// Current client
tx.executeSql("INSERT OR REPLACE INTO clientes (id, name, ...) " +
"VALUES " +
"(?,?,...)",
[cliente.id, cliente.name,...],
function(tx, res) {
var idclienteLocal = res.insertId;
// Client phones
telefonosCliente(tx, cliente, idclienteLocal).then(function() {
// Client credits
creditosCliente(tx, cliente, idclienteLocal).then(function() {
if (clientes.length === 0) {
resolve();
}
else {
procesarCliente(tx, clientes, clientes.shift());
}
}).catch(function(error) {
reject('Error créditos cliente ' + cliente.empresa + ': ' + error);
});
}).catch(function(error) {
reject('Error teléfonos cliente ' + cliente.empresa + ': ' + error);
});
}, function(tx, error) {
reject(error.message);
});
});
},
/**
* Clients insertion
* @param tx
* @param clientes
* @return {Promise}
*/
clientes = function(clientes) {
return new Promise(function(resolve, reject) {
var cliente,
clientesCont = clientes.length;
if (clientesCont === 0){
resolve();
}
else {
APP.db.transaction(function(tx) {
cliente = clientes.shift();
procesarCliente(tx, clientes, cliente).then(function() {
resolve();
}).catch(function(error) {
reject(error);
});
});
}
});
}
有关修复第二种方法的任何帮助,最重要的是如何让它在phonegap中工作?
编辑
我添加了一个验证码检查每个本地数据库中的表,而且奇怪的是,它apparenntly只创建两个表名为“不确定”和“项目”(我不”即使使用这样的表格)。
的验证码在这里:
if (APP.DEBUG) { // this is true
// Verify inserted data when triggered event 'app.load.all' just after the very last item in the DB has been inserted
$wrapper.on('app.load.all', function() {
APP.db.transaction(function(tx) {
console.log('Verifying DB');
tx.executeSql("SELECT name FROM sqlite_master WHERE type='table'", [],
function(tx, res) {
if (res.rows.length) {
$.each(res.rows, function(i, tabla) {
if (tabla.name !== '__WebKitDatabaseInfoTable__') {
console.log('Verifying table ' + tabla.name);
tx.executeSql("SELECT * FROM " + tabla.name, [],
function(tx, res) {
console.log("Table " + tabla.name + " has " + res.rows.length + " records");
},
function(tx, error) {
console.log('Error verifying table ' + tabla.name + ':' + error.message);
});
}
});
}
}, function(tx, error) {
console.log('Error verifying DB tables: ' + error.message);
});
});
});
}
这导致在这些线路的 “Web控制台” 过滤:
I/Web Console(14391): Verifying DB:1085
I/Web Console(14391): Verifying table undefined:1091
I/Web Console(14391): Verifying table item:1091
I/Web Console(14391): Error Verifying table undefined:no such table: undefined:1100
I/Web Console(14391): Error Verifying table item:no such table: item:1100
这是完全陌生的,我