如何在 Hyperledger composer 中做 URL 编码器
How to do URL encoder in Hyperledger composer
我需要在 logic.js 中使用特殊字符进行查询。我已经完成了查询逻辑。
当我将特殊字符作为参数之一时出现问题。
当我输入'ガガ'时,它找不到查询。当我把它的 URL 编码时,我可以找到查询结果。如何在 logic.js 中对我的特殊词进行编码以便查询我的词?
这是我的代码
/**
* Track the trade of a commodity from one trader to another
* @param {org.stock.mynetwork.Receive} receive - the receive to be processed
* @transaction
*/
async function receiveCommodity(receive) {
let statement = 'SELECT org.stock.mynetwork.Commodity WHERE (owner == _$owner AND dataType == _$dataType)';
let qry = buildQuery(statement);
//this works
let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'%E3%81%8C%E3%81%8C', dataType: receive.dataType });
//this dont
let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'がが', dataType: receive.dataType });
}
我在 SO 的错误一侧搜索 post,解决方案很简单
我只需要encodeURI(yourVariable.toString())
我需要在 logic.js 中使用特殊字符进行查询。我已经完成了查询逻辑。
当我将特殊字符作为参数之一时出现问题。
当我输入'ガガ'时,它找不到查询。当我把它的 URL 编码时,我可以找到查询结果。如何在 logic.js 中对我的特殊词进行编码以便查询我的词?
这是我的代码
/**
* Track the trade of a commodity from one trader to another
* @param {org.stock.mynetwork.Receive} receive - the receive to be processed
* @transaction
*/
async function receiveCommodity(receive) {
let statement = 'SELECT org.stock.mynetwork.Commodity WHERE (owner == _$owner AND dataType == _$dataType)';
let qry = buildQuery(statement);
//this works
let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'%E3%81%8C%E3%81%8C', dataType: receive.dataType });
//this dont
let allAssets = await query(qry, { owner: 'resource:org.stock.mynetwork.Trader#'+'がが', dataType: receive.dataType });
}
我在 SO 的错误一侧搜索 post,解决方案很简单
我只需要encodeURI(yourVariable.toString())