如何在jquery或javascript中同步调用 [英] How to synchronise call in jquery or javascript
问题描述
能否请您告诉我如何在jquery或java脚本中调用syncize方法. 实际的问题是我在click button上调用了一个函数,并获得了一些值.虽然在函数调用下方,并且一段时间后我得到的是未定义的值,但我会得到值. 我将用我的例子来解释. 1)我需要在单击del按钮上获取CASENAME值.我正在从数据库中获取值.在获取此deleteFolder函数调用的同时,我将获得未定义的值. 然后在我将在这里获得实际价值后alert("CASENAME" + CASENAME);我认为我需要像在Java中一样同步此方法.
can you please tell me how to call synchronise method in jquery or java script. Actually problem is that I call one function on click button.And get some value .While getting below function call and i am getting undefined value after some time i will get value. I will explain with my example. 1)I need to get CASENAME value on click del button.I am getting the value from data base .While getting this deleteFolder function call .There i will get value undefined. then after i will get real value here alert("CASENAME"+CASENAME);I think i need to synchronise this method as we do in 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)
});
});
}
推荐答案
您应该在...附近传递该变量( CASENAME )
You should be passing that variable (CASENAME) around...
或变量应在两个函数的范围内.
or the variable should be in the scope of both the functions.
尝试一下:
$(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)
});
});
}
这篇关于如何在jquery或javascript中同步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!