数组是空的我想访问数组arrcolumn []

时间:2017-01-10 08:48:54

标签: javascript jquery arrays json

我想访问我声明为全局数组的数组arrcolumn[]。我正在arrcolumn[]函数中初始化数组OnSuccess1()。我想在arrcolumn[]中使用OnSuccess()值在OnSuccess1()中初始化后的arrcolumn[]函数。 但OnSuccess()函数中var arrname = []; var arrmark = []; var arrcolumn = []; var arr = []; var arr1 = []; //display function function display() { $.ajax({ type: "POST", url: "Default.aspx/fetchStudent", data: '{}', contentType: "application/json;charset=utf-8", dataType: "json", success: OnSuccess, error: OnErrorCall }); $.ajax({ type: "POST", url: "Default.aspx/fetchcolumn", data: '{}', contentType: "application/json;charset=utf-8", dataType: "json", success: OnSuccess1, error: OnErrorCall1 }); function OnSuccess1(response) { var objdata1 = (response.d); var pm1 = JSON.parse(objdata1); var len1 = objdata1.length; arr1 = $.map(pm1, function(n, i) { var arr_temp1 = { 0: n.name } arrcolumn[i] = n.name; return arr_temp1; }); arrcolumn = jQuery.grep(arrcolumn, function(value) { return value != removeItem; }); arrcolumn = jQuery.grep(arrcolumn, function(value) { return value != removeItem1; }); alert(arrcolumn); } function OnErrorCall1(response) { alert("unable to fecth"); } function OnSuccess(response) { var objdata = (response.d); var pm = JSON.parse(objdata); var len = objdata.length; arr = $.map(pm, function(n, i) { var arr_temp = { 0: n.name1, 1: n.os, 2: n.cn, 3: n.pns, 4: n.dbms, 5: n.se, 6: n.c } arrname[i] = n.name1; arrmark[i] = [n.os, n.cn, n.pns, n.dbms, n.se, n.c]; return arr_temp; }); //alert(arrcolumn); alert(arrname); alert(arrmark); } function OnErrorCall(response) { alert("error occured"); } } 为空。

hdfsDirectory="hdfs://srcPath"   
 val conf = new org.apache.hadoop.conf.Configuration()
        val src:Path = new org.apache.hadoop.fs.Path(hdfsDirectory)
        val fs = FileSystem.get(src.toUri,conf)
        val srcPath: Path = new Path("hdfs://srcPath")
        val srcFs =FileSystem.get(srcPath.toUri,conf)
        val dstPath:Path =new Path("hdfs://targetPath/")
        val dstFs =FileSystem.get(dstPath.toUri,conf)
        val exists = fs.exists(new org.apache.hadoop.fs.Path(hdfsDirectory))
        val status:Array[FileStatus] = fs.listStatus(new Path(hdfsDirectory))
        if (status.length>0) {
          status.foreach(x => {
            println("My files: " + x.getPath)
            FileUtil.copy(srcFs, x.getPath, dstFs, dstPath, true, conf)
            println("Files moved !!" +x.getPath)
          }
          )}
        else{
          println("No Files Found !!")
        }

1 个答案:

答案 0 :(得分:1)

您无法保证在OnSuccess1之后调用OnSuccess。如果您在完成工作之前需要两条信息,则需要等待两个电话完成。

一个简单的方法是jQuery的$.when

$.when(
    $.ajax(/*...*/), // The first call
    $.ajax(/*...*/)  // The second call
).then(function(result1, result2) {
    // Both calls are done now. Use `result1` (the result of the
    // first call) and `result2` (the result of the second) here
});

调用将并行运行,但在两个调用完成之前,最后的处理程序将不会运行。