在将数据插入表之前,我需要检查重复的列(项目)。但它是异步调用。所以它不工作。我需要调用同步调用,以便我可以获得值true 和 false
然后检查插入值与否。
function validationField() {
db.transaction(getallTableCntend, errorCB);
}
function getallTableCntend(tx) {
tx.executeSql('SELECT * FROM CaseTable', [], queryexcecute, errorCB);
}
function queryexcecute(tx, result) {
var len = result.rows.length;
for (var i = 0; i < len; i++) {
if(result.rows.item(i).CaseName ==$('.caseName_h').val()){
alert("Folder is already Exit.");
isvalid=false;
Break;
return;;
}
}
}
I am calling this like this.
$(document).on('click', '#AddButton', function() {
isvalid = validationField();
if (isvalid) {
insertData();
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onFileSystemFail);
}
});
我可以像那样创建表.. tx.executeSql('CREATE TABLE IF NOT EXISTS CaseTable (id INTEGER PRIMARY KEY AUTOINCREMENT, CaseName TEXT NOT NULL UNIQUE,CaseDate INTEGER ,TextArea TEXT NOT NULL)'); 并像那样使用...
tx.executeSql('INSERT OR IGNORE INTO CaseTable(CaseName,CaseDate,TextArea) VALUES ("' + $('.caseName_h').val() + '", "' + $('.caseDate_h').val() + '","' + $('.caseTextArea_h').val() + '")');
----------------------------------------------这样做- -------------
function checkExitingFolderName(){
db.transaction(getallTableCntend, errorCB);
}
function getallTableCntend(tx) {
tx.executeSql('SELECT 1 FROM CaseTable WHERE CaseName ='+$('.caseName_h').val(), [], queryexcecute, errorCB);
}
function queryexcecute(tx, result) {
var len = result.rows.length;
alert("hi"+length);
if(len>0){
alert("Folder")
}
else{
insertData();
}
}