0

似乎来自json的地图确实需要时间,我想用promise来等待它。

formatDataOutput: function (jsonData) {
    return new Promise(function (resolve, reject) {
        let a = JSON.parse(jsonData)
        let b = data.b.map(p => ({ store: p[0], surname: p[1] }))
        let l = data.l.map(p => ({ store: p[0], surname: p[1] }))
        let e = data.e.map(p => ({ store: p[0], address: p[1] }))
        let eT = data.eT.map(p => ({ store: p[0], address: p[1], name: p[2] }))
        let bx = data.bx.map(p => ({ store: p[0], surname: p[1] }))
        let e = data.e.map(p => ({ store: p[0], address: p[1] }))
        let eT = data.eT.map(p => ({ store: p[0], address: p[1], name: p[2] }))
        let t = data.t.map(p => ({ store: p[0], address: p[1] }))
        let tT = data.tT.map(p => ({ store: p[0], address: p[1], name: p[2] }))
        let x = data.x.map(p => ({ store: p[0], address: p[1], viewkey: p[2] }))
        let formattedData = {
            b: b,
            l: l,
            e: e,
            eT: eT,
            bx: bx,
            e: e,
            eT: eT,
            t: t,
            tT: tT,
            x: x
        }
        console.log(formattedData) // -> Its correct
        resolve(formattedData)
    })
}


func.formatDataOutput(data).then((formattedData) => {
    reply.send(formattedData) // -> Its {}
})

我试过Promise.all了,它返回非Iterable,基本上我需要输出formattedData,当它准备好时。

4

0 回答 0