在我的hyperledger composer应用程序中,我向事务处理器功能(在文件logic.js中)添加了一些编程访问控制。
我添加的代码行之一抛出错误:
这是代码行:
for (consultantRef of transaction.newConsultants) {
//the following line of code does NOT work:
let consultantId = consultantRef.split('#')[1];
在控制台中,我收到以下错误消息:
"transaction returned with failure: TypeError: consultantRef.split is not a function"
为澄清起见:
transaction.newConsultants是以下类型的数组:
[“ resource:org.comp.app.Consultant#id1”,“ resource:org.comp.app.Consultant#id2”, “ resource:org.comp.app.Consultant#id3”]
我想获取各个顾问的ID(例如“ id1”)。
根据文档(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split),拆分功能确实存在。
但是它不起作用。
如何获取顾问的ID?
更新:
当我在控制台中查看事务的属性时,对于属性“ newConsultants”,我看到以下内容:
newConsultants: Array (1)
0 "resource:org.comp.app.Consultant#john.doe@gmail.com_1535655902439"
Array Prototype
为澄清起见: 事务是一个对象,即以下对象(从有角度的前端复制):
this.transaction = {
$class: 'org.comp.app.AddToConsultantsOfProject',
'project': 'resource:org.comp.app.project#' + this.projectId,
'newConsultants': this.selectedConsultants,
'timestamp': new Date().getTime()
};
答案 0 :(得分:1)
它是因为它是资源。您可能会将其转换为字符串(然后拆分将在字符串对象上可用-但您仍然需要删除(转换后的资源的)尾随字符)。
还有一种更好的方法-尝试类似的事情:
trxn.newConsultants.forEach((consultantRef) => {
console.log("identifier is " + consultantRef.getIdentifier());
});
getIdentifier()
在Composer API文档中进行了描述。