客户端上的空对象。如何正确传递承诺值?

我遇到了对象的问题,它包含承诺值并在Cilent端访问它们。我想访问值,但我收到的只是空的对象。客户端上的空对象。如何正确传递承诺值?

这里是服务器端的代码:

router.get('/toExcess', function(req, res){ 

console.log(req.query);

const response = logic.adder(req.query.a, req.query.b);

const convertToModular = logic.modularRecordExcess(response);

const convertToOpposite = logic.oppositeRecordExcess(response);

const convertToObjective = logic.objectiveRecordExcess(response);

convertToObjective.then(function (response) {

var add = {

modular: convertToModular,

opposite: convertToOpposite,

objective: convertToObjective,

}

console.log(add);

res.send(add);

}).catch(function(err){

});

});

,它是在服务器端控制台日志:

{ modular: Promise { [ '1.', '0111', '.', '1001', '0011' ] }, 

opposite: Promise { [ '1.', '1000', '.', '0110', '1100' ] },

objective: Promise { [ '1.', '1000', '.', '0110', '1101' ] } }

和这里的反应函数:

showExcess(){ 

document.querySelector('.input-wrapper').style.display = 'inline';

RestClient.getExcess(this.state.augend, this.state.addend).then((response)

=> {

this.setState({

isReady: true

});

console.log(response);

});

}

和浏览器中的CONSOL.log结果: enter image description here

对象为空。 有什么建议吗?我需要获得模块化,客观和相反的价值观。

回答:

router.get('/toExcess', function(req, res){ 

console.log(req.query);

const response = logic.adder(req.query.a, req.query.b);

const convertToModular = logic.modularRecordExcess(response);

const convertToOpposite = logic.oppositeRecordExcess(response);

const convertToObjective = logic.objectiveRecordExcess(response);

Promise.all([convertToModular, convertToOpposite, convertToObjective])

.then(function (response) {

var add = {

modular: response[0],

opposite: response[1],

objective: response[2],

}

console.log(add);

res.send(add);

//or you can pass res.json(response);

})

.catch(function(err){

});

});

以上是 客户端上的空对象。如何正确传递承诺值? 的全部内容, 来源链接: utcz.com/qa/261994.html

回到顶部