这是一个函数-f()。我希望它返回更新的“ numberOf”。 FetchDataMyData()是对api的获取请求。我想更新numberOf值,然后返回它。
async function f() {
let numberOf = 0
let result = await fetchDataMyData((r) => {
numberOf = r.length
console.log(r.length)
});
return numberOf
}
console.log(f())
这是fetchDataMyData()的代码
var fetchDataMyData = (callback) => {
const DataUrl3 = '/api/getCustomerLogsAndTasks/' + IdNo;
reqwest({
url: DataUrl3,
type: 'json',
method: 'get',
contentType: 'application/json',
success: (res) => {
var notification = []
res.map((item, key) => {
if (item.statusOfTaskOrLog === 'uncompleted') {
console.log(item)
notification.push(item)
}
})
callback(notification);
},
});
}