0

你能告诉我如何在 jquery 或 java 脚本中调用同步方法吗?实际上的问题是我在单击按钮上调用了一个函数。并获得了一些价值。虽然低于函数调用,但一段时间后我得到了未定义的值,我将获得价值。我会用我的例子来解释。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)
          });

      });

    }
4

1 回答 1

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)
            });

    });

}
于 2013-07-17T05:17:09.457 回答