问题:
我创建了一个链码。在此代码的一个函数中,我调用了同一链码的另一个函数。该代码就是这样。
async nthUsersLands(stub, args) {
if (args.length != 1) {
throw new Error(
"Incorrect number of arguments. Expecting NIC ex: 942990014V"
);
}
let nic = args[0];
let queryString = {};
queryString.selector = {};
queryString.selector.docType = "land";
queryString.selector.user = nic;
let method = thisClass["getQueryResultForQueryString"];
let queryResults = await method(
stub,
JSON.stringify(queryString),
thisClass
);
// let queryResults = await methods.getQueryResultForQueryString(stub,JSON.stringify(queryString))
console.log(queryResults.toString());
return queryResults;
}
async getQueryResultForQueryString(stub, queryString, thisClass) {
console.info("- getQueryResultForQueryString queryString:\n" + queryString);
let resultsIterator = await stub.getQueryResult(queryString);
let method = thisClass["getAllResults"];
let results = await method(resultsIterator, false);
// let results = await methods.getAllResults(resultsIterator,false)
return Buffer.from(JSON.stringify(results));
}
async getAllResults(iterator, isHistory) {
let allResults = [];
while (true) {
let res = await iterator.next();
if (res.value && res.value.value.toString()) {
let jsonRes = {};
console.log(res.value.value.toString('utf8'));
if (isHistory && isHistory === true) {
jsonRes.TxId = res.value.tx_id;
jsonRes.Timestamp = res.value.timestamp;
jsonRes.IsDelete = res.value.is_delete.toString();
try {
jsonRes.Value = JSON.parse(res.value.value.toString('utf8'));
} catch (err) {
console.log(err);
jsonRes.Value = res.value.value.toString('utf8');
}
} else {
jsonRes.Key = res.value.key;
try {
jsonRes.Record = JSON.parse(res.value.value.toString('utf8'));
} catch (err) {
console.log(err);
jsonRes.Record = res.value.value.toString('utf8');
}
}
allResults.push(jsonRes);
}
if (res.done) {
console.log('end of data');
await iterator.close();
console.info(allResults);
return allResults;
}
}
}
但是当我调用此getNthUsersLands时,会出现这样的错误。
TypeError:无法读取的属性'getQueryResultForQueryString' 未定义
我尝试了很多方法来找到关于堆栈溢出中与该问题有关的三个问题的解决方案,但我无法使用这些问题来解决此问题。有人可以帮我解决这个问题吗?谢谢!