我需要插入三件事
async.waterfall
方法有insertCountry
insertcountry
包含以下逻辑:
var listofCountry = "source file to read the list of country" //a file is there from where i read the countries
listofCountry.forEach(function(objCountry) {
createCountry(data, next) //with some logic i have my data object already filled.
createState() //in this method i need to pass the countryId that i have just created.
}, this);
//this is the method that will carry insert of country, **Request data** is a generic method and works fine.
function createCountry(data, next) {
Request(data, {
api: "myApi",
uri: "/Country/create",
method: "POST",
data: {
"name": "data.CountryName",
}
},
function(error, response) {
if (response && response.data !== undefined && response.data !== null) {
data.countryId = response.data.CountryId; // the debugger is not coming here.hence not setting the countryId
} else if (response && response.error !== undefined && response.error !== null) {
error = response.error;
}
});
}
我觉得async
或callback
的实施方式不正确,我不确定。