我是新的Node.JS开发人员。 我有一个问题,当我用Dictionary格式调用函数参数时。那么被调用的函数无法执行,为什么?
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");
}
结果:
进入testFunction;
原始代码如下:
//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");
......
}
结果: 客户succ 1 1 1 1 0 0 材料succ 1 1 1 1 1 0 uom succ 1 1 1 1 1 1 go uom succ
答案 0 :(得分:0)
你在“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);
}