js 获得了字符串但return 的值是"[object Promise]"
const into = async (ids) => {
const numbersArray = ids.split('').map(Number)
const fetchData = async (number) => {
if (number) {
const data = await tubeApi.getAnyDevices({ id: number })
return data && data.deviceName ? data.deviceName : ''
}
return ''
}
const result = Promise.all(numbersArray.map(fetchData))
return (await result).filter(Boolean)
}
const intoText = async (ids) => {
if (ids) {
let getit = await into(ids)
console.log(getit.join(','))
return getit.join(',')
}
}
打印结果没问题
看了一些帖子写成现在这样还是一样结果,我承认我对propmise的理解稀碎。。。怎么才能把字符串显示出来呢
intoText函数是async函数,他将返回一个promise,所以你不能直接将intoText的返回值赋值到某个变量上,应该在回调中进行赋值
intoText().then(txt => xxx.xxx = txt)