首页 > 解决方案 > 如何控制资产中的日志值?在超级账本作曲家中?

问题描述

我正在通过超级账本作曲家游乐场编写网络。

在这里,我有一个名为patient的资产,而patient医院列表,我有一个名为GetPatientHospitals的事务,用于调用函数getPatientHospitals,我希望这个函数打印出一个 ID 列表(例如resource:org. acme.patientchain.PatientHospital#5wyjftthjr当我测试时),但是当我测试我的功能时,它只告诉我我的交易已经提交,我看不到输出,有什么办法吗?或者我需要其他资产来存储这些消息?

我的 getPatientHospitals函数:

function getPatientHospitals(gethospitals){
    return getAssetRegistry('org.acme.patientchain.Patient')
         .then(function (PatientAssetRegistry) {
    // Get the patient asset
        return  PatientAssetRegistry.get(gethospitals.patient.pubKeyPatient);
     })
  .then(function (patienthospital) {
    return patienthospital.hospitals;
  })
} //list of hospitals

我的GetPatientHospitals交易和患者资产:

transaction GetPatientHospitals { 
--> Patient patient
}



asset Patient identified by pubKeyPatient {
 o String pubKeyPatient 
--> PatientHospital[] hospitals

}

这是我测试的一名患者的医院:

{
  "$class": "org.acme.patientchain.Patient",
  "pubKeyPatient": "1652",
  "hospitals": [
    "resource:org.acme.patientchain.PatientHospital#5wyjftthjr",
    "resource:org.acme.patientchain.PatientHospital#mgnl6ag4vh",
    "resource:org.acme.patientchain.PatientHospital#5wyjftthjr"
  ]
}

我想打印这些资源或仅打印#之后的 id

但是我在任何地方都看不到输出,我可以在这个操场上“打印”吗?

标签: hyperledgerblockchainhyperledger-composer

解决方案


您可以console.log()在 js 文件中使用。然后您可以在浏览器开发者控制台中看到输出。对于 Firefox 和 Chrome,您可以使用CTRL-SHIFT-I显示开发者控制台。这仅在您使用带有“Web”配置文件的 Playground 时才有效,然后您将在浏览器控制台中看到 console.log 输出。如果您使用连接到本地 Fabric 实例的 Playground,则 console.log 输出将在 Chaincode 容器的日志中。

尝试使用console.log(patienthospital.hospitals)并检查开发人员控制台中的输出。


推荐阅读