hyperledger-composer - 为什么后续 HLC 查询返回未定义?
问题描述
我想通过其 ID 检索参与者并将详细信息记录到控制台。我已经使用命名作曲家查询来检索参与者。访问控制是自动生成的(默认)。
模型文件为:
namespace org.example.empty
participant SampleParticipant identified by partId {
o String partId
o String LName
o String FName
}
transaction getSampleParticipant {
o String partyId
}
查询.qry 文件:
query selectParticipantById {
description: "Select participant by Id"
statement:
SELECT org.example.empty.SampleParticipant
WHERE (partId == _$pId)
}
事务处理器是:
/**
* get a participant.
* @param {org.example.empty.getSampleParticipant} txgetParty
* @transaction
*/
async function getParty (txgetParty) {
const queryResult = await query ('selectParticipantById', {pId: txgetParty.partyId})
console.log('Participant detail.')
console.log(queryResult.partId)
console.log(queryResult.FName)
console.log(queryResult.LName)
}
在 Composer 操场上安装后,我创建了一个 SampleParticipant 并提交 getSampleParticipant 事务。控制台输出三遍“未定义”。我错过了什么?
解决方案
我发现查询返回一个对象数组。因此,使用for
循环访问数组元素将解决问题。
for (let index= 0; index< queryResult.length; n++) {
console.log("partId: " + queryResult[index].partId );
console.log("First Name: " + queryResult[index].FName);
console.log("Last Name: " + queryResult[index].LName);
}
推荐阅读
- database - 在循环上创建具有四种状态的动态元素
- node.js - 我在heroku中部署了一个反应应用程序,但只有当我使用自己的系统时,我才能通过应用程序将表单发送到mongodb
- php - 如何 jquery 选择 $("#div_id").html(' php echo?
- react-select - React-select 地址自动完成出现在 Chrome 中
- tsql - 在此上下文中不允许使用名称“xxx”。有效表达式是常量、常量表达式和(在某些情况下)变量
- javascript - 实时求和表单列
- linux-device-driver - 全新安装在 HP Elitebook 840 G7 中后,触摸板在 Cent OS 7.9 中完全不工作
- delphi - 用于将 TClientDataSet 数据分组和聚合到另一个数据集中的内置解决方案
- python - 打印警告 - sqlalchemy
- python - 未显示西班牙地区的 Plotly Choropleth 地图