gpt4 book ai didi

javascript - Async.js waterfall (在数组外定义的函数)

转载 作者:搜寻专家 更新时间:2023-11-01 00:26:37 24 4
gpt4 key购买 nike

我是第一次使用 async.js,想将函数数组分离成单独的函数。我有:

工作代码

    async.waterfall([
function(callback)
{
var querySuccess = function (tx, result)
{
callback(null, result.rows.item(0).EventImportTime || "");
};

var queryError = function (tx, e)
{
callback("Query Error")
};

database.open();
database.query("SELECT EventImportTime FROM Contact WHERE Contact.Id = ?", [contactId], querySuccess, queryError);
},
function(lastImportTime, callback)
{
var url = "";
url += 'MobileGetvents.aspx?';
url += '&LastImportTime=';
url += lastImportTime;
url += '&Format=JSON';

callback(null, url)
},
],
function(err, result)
{
if (err)
console.log("Error Happened");
else
{
console.log(result);
getJSON(result, callback,

errorCallback)
}
})

我要

async.waterfall([
getLastImportTime(callback) ,
buildUrl(lastImportTime, callback),
],
//callback
);

但是当我运行这段代码时它总是返回

Uncaught ReferenceError: lastImportTime is not defined

最佳答案

我会假设你想要这个:

var getLastImportTime = function(callback) { };
var buildUrl = function(lastImportTime, callback) { };

async.waterfall([
getLastImportTime,
buildUrl,
],
//callback
);

关于javascript - Async.js waterfall (在数组外定义的函数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10599574/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com