将带有_(下划线)的fabric模型转换为convector/json对象的最佳方法是什么
当我收到frabric模型时,我收到的是一个带有下划线ex的模型
JSON.stringify(participant, undefined, 2)
"{
"_id": "gov",
"_identities": [
{
"fingerprint": "75:7B:3F:16:C8:0F:FA:15:4A:B9:7D:2B:AE:85:76:1F:75:A3:C5:05",
"status": true
}
],
"_msp": "org1MSP",
"_name": "Big Government",
"_type": "io.worldsibu.examples.participant"
}"提前感谢
发布于 2019-09-01 01:22:10
@diestrin:包装你在模型本身中得到的响应,比如: new Participant(participant).toJSON()或者更好,在控制器中发送它之前,已经像一个JSON一样发送它了。
发布于 2019-09-01 01:33:50
我们必须使用对流模型来进行转换,
@diestrin:这是一个可以正确删除道具中的_的逻辑
上面我们有一个将fabric转换为对流模型的方法,用于graphql api中,带有typegraphql
async findOneById(id: string): Promise<Participant> {
try {
// get fabric model with _props
const participant: Participant = await ParticipantControllerBackEnd.get(id);
// convert fabric model to convector module _props
const participantModel = new ParticipantConvectorModel(participant).toJSON();
// trick: must return convector model as a graphql model, to prevent property conversion problems
return (participantModel as Participant);
} catch (error) {
throw error;
}
}注释行的
说明
https://stackoverflow.com/questions/57740181
复制相似问题