即時通訊使用npm plaid我希望能夠訪問此plaidClient.getTransactions
以外的variable trans
。由於如何訪問回調內的局部變量功能外
var trans;
var startDate = moment().subtract(30, 'days').format('YYYY-MM-DD');
var endDate = moment().format('YYYY-MM-DD');
plaidClient.getTransactions(AccessToken, startDate, endDate, {
count: 250,
offset: 0,
}, function(error, transactionsResponse) {
if (error != null) {
console.log(JSON.stringify(error));
return response.json({
error: error
});
}
var trans = transactionsResponse
});
var trans //should work here
這可能會幫助你[鏈接](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call ) –
*去商店買冰淇淋。 * =>你得到一個空的冰淇淋:/ –