我有一个功能:
function RetrieveCountryCode(countryName,callback) {
Country.find({ name: countryName },function(err,country) {
if (err) {
callback(err,null);
} else {
callback(null,country.code);
}
});
}
我正在这样使用它:
//find a country code of a given country by user
var userCountryCode = null;
RetrieveCountryCode(country,countryCode) {
if (err) {
console.log(err);
}
userCountryCode = countryCode;
});
console.log("COUNTRY CODE");
console.log(userCountryCode);
*为函数指定的参数“国家/地区”来自html表单,已正确传递,我对此进行了检查。
我仍然在控制台中得到相同的响应:国家代码空。我在做什么错...?