简体   繁体   中英

express.js response value as destruct

I think this is kind of destructuring problems..

My node.js server have to return

{
    "result" : true,
    "values" : [{
            "request_id": <string>,
            "product_name": <string>,
            "ratio": <float>,
            "buyers": [


        },
        ...
    ]
}

but it returns

{"result":true,
"values":{"values":[{"results":[{"rank":1,"buyer_id":"Z0195841"},{"rank":2,"buyer_id":"Z0186008"},

I think this part is the problem.

 res.json({ "result" : true,
            "values" : values});

so I edit like this,

  res.json({ "result" : true,
               values});

it didn't works. still return

{"result":true,
"values":{"values":[{

How can I solve this??? please help.

I think that you have a "value" inside other "value" key, try destructuring it, this way:

const { value } = value;

res.json({ 
    "result" : true,
    values
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM