gpt4 book ai didi

javascript - 风 sails : how to get a value outside of the function

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

我正在尝试从函数中获取 count 值并希望存储在函数外部。

var count;      
client.count({
index: 'employee',
type: 'details',
}, function (err, response) {
if(err){console.log(err)}
count = response.count
console.log(count);
});

控制台日志(计数);我想在函数之外使用这个计数。这可能吗?

最佳答案

尝试以这种方式编写代码:

client.count({
index: 'employee',
type: 'details',
}, afterCount);
function afterCount(err, count){
if (err) console.log(err);
// do whatever you want with count
// if there's too much logic, split it into functions and send count as a param to them
}

关于javascript - 风 sails : how to get a value outside of the function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32434043/

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