请告诉我如何在jquery或java脚本中调用synchronize方法。 实际上问题是我在点击按钮上调用了一个函数。并获得了一些值。虽然获得了函数调用以下,并且在一段时间后我将获得未定义的值,我将获得价值。 我会用我的例子来解释。 1)我需要在点击del按钮上获取CASENAME值。我从数据库中获取值。同时获取此deleteFolder函数调用。我将获得未定义的值。 之后我会在这里得到真正的价值警报(“CASENAME”+ CASENAME);我想我需要像在java中那样同步这个方法。?
$(document).on('click', '.del', function(event) {
ROW_ID = $(this).closest(".caseRowClick").attr("id");
//getCaseNameValue();
db.transaction(function (tx) {
var caseName_h = $('.caseName_h').val();
$yoursql = 'SELECT CaseName FROM CaseTable WHERE id ='+ ROW_ID;
tx.executeSql($yoursql, [], function (tx, results) {
CASENAME=results.rows.item(0).CaseName;
alert("CASENAME"+CASENAME);
});
});
deleteData();
deleteFolder();
$(".ctrl").toggleClass("togg");
event.stopPropagation();
});
function deleteFolder(){
alert(CASENAME);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
console.log("Root ================********************* " + fs.root.fullPath);
TEXTFILE_PATH=fs.root.fullPath;
fs.root.getDirectory(CASENAME, {create: true, exclusive: false},
function(dirEntry) {
dirEntry.removeRecursively(successfullyDelete, faildelete)
});
});
}
答案 0 :(得分:0)
您应该将该变量( CASENAME )传递给...
或变量应该在两个函数的范围内。
试试这个:
$(document).on('click', '.del', function (event) {
var ROW_ID = $(this).closest(".caseRowClick").attr("id");
var CASENAME;
//getCaseNameValue();
db.transaction(function (tx) {
var caseName_h = $('.caseName_h').val();
$yoursql = 'SELECT CaseName FROM CaseTable WHERE id =' + ROW_ID;
tx.executeSql($yoursql, [], function (tx, results) {
CASENAME = results.rows.item(0).CaseName;
alert("CASENAME" + CASENAME);
});
});
deleteData();
deleteFolder(CASENAME);
$(".ctrl").toggleClass("togg");
event.stopPropagation();
});
function deleteFolder(CASENAME) {
alert(CASENAME);
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
console.log("Root ================********************* " + fs.root.fullPath);
TEXTFILE_PATH = fs.root.fullPath;
fs.root.getDirectory(CASENAME, {
create: true,
exclusive: false
},
function (dirEntry) {
dirEntry.removeRecursively(successfullyDelete, faildelete)
});
});
}