Node.JS调用函数可以';我不喜欢字典

Node.JS调用函数可以';我不喜欢字典,node.js,dictionary,Node.js,Dictionary,我是Node.JS的新开发者。 当我用字典格式调用函数参数时,我有一个问题。那么调用的函数就不能执行了,为什么 function testFunction(allObjects, test, response) { console.log("go in testFunction"); var dic = {a: "aaa", b:"bbb"}; testFunctionTo(dic, response); } function testFunctionTo(dic, respon

我是Node.JS的新开发者。 当我用字典格式调用函数参数时,我有一个问题。那么调用的函数就不能执行了,为什么

function testFunction(allObjects, test, response) {
  console.log("go in testFunction");

  var dic = {a: "aaa", b:"bbb"};
  testFunctionTo(dic, response);
}

function testFunctionTo(dic, response) {

  console.log("go in testFunctionTo");
  response.send("success");
}
结果:

进入测试功能

原始代码如下所示:

//generate and mapping all master data from this import
function prepareMasterRequireData(allObjects, response) {

  var singleCustomer = {}; //id: ParseObjectId
  var singleCustomerData = {}; //id: syncLog
  var singleMaterial = {}; //id: ParseObjectId
  var singleMaterialData = {}; // id: syncLog
  var singleUom = {}; //id: ParseObjectId
  var singleUomData = {}; // id: syncLog
  var singleOrderHeader = {}; //id: ParseObjectId
  var singleOrderHeaderData = {}; //id: syncLog

  //prepare single data
  for (var i=allObjects.length-1; i>=0; i--) {

    var syncLog = allObjects[i];
    if (syncLog.get("TypeFlag") == "A") {
      //prepare for customer
      var customerId = syncLog.get("Customer_SN");
      if (singleCustomer[customerId] == null) {
        singleCustomer[customerId] = "";
        singleCustomerData[customerId] = syncLog;
      }

      //prepare for material
      var materialId = syncLog.get("Product_SN");
      if (singleMaterial[materialId] == null) {
        singleMaterial[materialId] = "";
        singleMaterialData[materialId] =  syncLog;
      }

      //prepare for uom
      var UomId = syncLog.get("Product_Unit");
      if (singleUom[UomId] == null) {
        singleUom[UomId] = "";
        singleUomData[UomId] = syncLog;
      }

      //prepare for Orderheader
      var orderId = syncLog.get("Order_SN_Master");
      if (singleOrderHeader[orderId] = null) {
        singleOrderHeader[orderId] = "";
        singleOrderHeaderData[orderId] = syncLog;
      }
    } else {
      delete allObjects[i];
    }

  }

  var customerCount = Object.keys(singleCustomer).length;
  var materialCount = Object.keys(singleMaterial).length;
  var UomCount = Object.keys(singleUom).length;

  var currentCustomerCount = 0;
  var currentMaterialCount = 0;
  var currentUomCount = 0;


  for (key in singleCustomer) {
    getCustomerID(key, singleCustomerData[key], {
      success: function(key, objectId) {
        singleCustomer[key] = objectId;
        currentCustomerCount ++;

        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("customer succ " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {
          console.log("go customer succ");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }

      },
      error: function(key, error) {
        currentCustomerCount ++;

        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("customer fail " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {
          console.log("go customer fail");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }
      }
    });
  }

  for (key in singleMaterial) {
    getMaterialId(key, singleMaterialData[key], {
      success: function(key, objectId) {
        singleMaterial[key] = objectId;
        currentMaterialCount ++;

        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("material succ " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {
          console.log("go material succ");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }

      },
      error: function(key, error) {
        currentMaterialCount ++;
        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("material fail " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {
          console.log("go material fail");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }
      }
    });
  }

  for (key in singleUom) {
    getUOMId(key, singleUomData[key], {
      success: function(key, objectId) {
        singleUom[key] = objectId;
        currentUomCount ++;

        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("uom succ " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {


          //testFunctionTo(singelCustomer, response);
          console.log("go uom succ");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }

      },
      error: function(key, error) {
        currentUomCount ++;

        var stringValue = customerCount + " " + materialCount + " " + UomCount + " " +currentCustomerCount + " " +currentMaterialCount + " " + currentUomCount;
        console.log("uom fail " + stringValue);
        if ((currentCustomerCount == customerCount) && 
            (currentMaterialCount == materialCount) &&
            (currentUomCount == UomCount)) {
          console.log("go uom fail");
          updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
        }
      }
    });
  }


  //response.send(resultString);

}

//update syncLog for this import
function updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response) {
  console.log("yes in update");
  ......
}
结果: 客户成功1 0 0 物料成功1 0 计量单位成功1
go uom succ

您在“console.log(“go material succ”);”的同一块中调用该函数,并且“go material succ”没有打印出来,这意味着它没有进入if条件

    if ((currentCustomerCount == customerCount) && 
        (currentMaterialCount == materialCount) &&
        (currentUomCount == UomCount)) {
      console.log("go material succ");
      updateImportMasterData(allObjects, singelCustomer, singleMaterial, singleUom, singleOrderHeader, response);
    }

调用
testfunction to
function之前是否还有其他代码(逻辑)?没有,上面的代码是这样的。您可以发布完整的代码吗?发布,上面您可以查看