使用lodash将服务响应对象值转换为数组

时间:2018-06-21 15:09:27

标签: javascript reactjs

不确定这是怎么回事

const info= getUserInfo('michael').then(response => {
      return _.map(response, value => {
        return value.Symbol
      })
    })

服务响应为

//console.log(response)
    0:{UserId: "michael", Symbol: "ABC"}
    1:{UserId: "michael", Symbol: "ABD"}
    2:{UserId: "michael", Symbol: "XYZ"}
    3:{UserId: "michael", Symbol: "ZYX"}
    4:{UserId: "michael", Symbol: "CBA"}

在console.log中,我收到一个Promise响应,我不明白为什么

//console.log(info)
Promise {_bitField: 0, _fulfillmentHandler0: undefined, _rejectionHandler0: undefined, _promise0: undefined, _receiver0: undefined, …} 

返回的符号在_rejectionHandler0

我的愿望回报是['ABC', 'ABD', 'XYZ', 'ZYX', 'CBA']

1 个答案:

答案 0 :(得分:0)

尝试

const info= getUserInfo('michael').then(response => {
    return _.map(response, value => {
        return value.Ticker
    })
})

您正在访问Symbol,它不在您的响应中。应该是Ticker