Javascript 通过异步方法可以使用ux.sumBy

Javascript 通过异步方法可以使用ux.sumBy,javascript,asynchronous,lodash,Javascript,Asynchronous,Lodash,我的问题是,使用异步方法知道lodash(sumBy)值的可能和: const total=uu.sumBy(taxes,t=>asyncMethodExample(t.amount)) 这样使用它是不可能的。期望第二个参数返回要求和的值,而不是承诺 您可以这样做: const total = _.sum(await Promise.all(taxes.map(t => asyncMethodExample(t.amount)))); 那样使用它是不可能的。期望第二个参数返回要求和的值,

我的问题是,使用异步方法知道lodash(sumBy)值的可能和:


const total=uu.sumBy(taxes,t=>asyncMethodExample(t.amount))

这样使用它是不可能的。期望第二个参数返回要求和的值,而不是承诺

您可以这样做:

const total = _.sum(await Promise.all(taxes.map(t => asyncMethodExample(t.amount))));

那样使用它是不可能的。期望第二个参数返回要求和的值,而不是承诺

您可以这样做:

const total = _.sum(await Promise.all(taxes.map(t => asyncMethodExample(t.amount))));
Promise.all(taxes.map(t=>asynchmethodexample(t.amount)).then(u.sum).then(console.log,console.error)
Promise.all(taxes.map(t=>asynchmethodexample(t.amount)).then(u.sum).then(console.log,console.error)