Hyperledger-Composer:无法从交易处理器函数中访问 javaScript split()-函数
Hyperledger-Composer: not able to access javaScript split()-function from within transaction processor function
在我的 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
澄清一下:
transaction 是一个对象,即如下(从angular前端复制过来的):
this.transaction = {
$class: 'org.comp.app.AddToConsultantsOfProject',
'project': 'resource:org.comp.app.project#' + this.projectId,
'newConsultants': this.selectedConsultants,
'timestamp': new Date().getTime()
};
因为它是一个资源。您可能会将其转换为字符串(然后 split 将在字符串对象上可用 - 但您仍然需要删除尾随字符(转换后的资源))。
有更好的方法 - 尝试类似的方法:
trxn.newConsultants.forEach((consultantRef) => {
console.log("identifier is " + consultantRef.getIdentifier());
});
getIdentifier()
在 Composer API 文档中有描述。
在我的 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
澄清一下: transaction 是一个对象,即如下(从angular前端复制过来的):
this.transaction = {
$class: 'org.comp.app.AddToConsultantsOfProject',
'project': 'resource:org.comp.app.project#' + this.projectId,
'newConsultants': this.selectedConsultants,
'timestamp': new Date().getTime()
};
因为它是一个资源。您可能会将其转换为字符串(然后 split 将在字符串对象上可用 - 但您仍然需要删除尾随字符(转换后的资源))。
有更好的方法 - 尝试类似的方法:
trxn.newConsultants.forEach((consultantRef) => {
console.log("identifier is " + consultantRef.getIdentifier());
});
getIdentifier()
在 Composer API 文档中有描述。