Node.js nodejs中insert的循环遍历方法
有三件事我需要插入Node.js nodejs中insert的循环遍历方法,node.js,asynccallback,Node.js,Asynccallback,有三件事我需要插入 国家 陈述 城市 async.falter方法具有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, n
async.falter
方法具有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;
}
});
}
我觉得
异步
或回调
的实现不正确,我不确定。您能发布完整的异步代码吗?您没有向我们展示瀑布部分+您从未在createCountry中调用next吗?您能发布完整的异步代码吗?您没有向我们展示瀑布部分+您从未在createCountry中调用next