我导出的函数参数值返回为未定义,但是我的其他函数以相同的方式工作。希望您能提供帮助!
顺便说一句-我知道并不是所有参数都包括在内,但直到现在还没有起作用!
在我的postRequests.js文件中不起作用的函数:
exports.getRefundCalculationApiCall = function (itemId, ngrokUrl, domain, orderId) {
console.log('ngrokurl 2' + ngrokUrl)
console.log('domain2' + domain)
console.log('orderId2' + orderId)
console.log('itemId2' + itemId)
httpRequest.post(
`${ngrokUrl}/${domain}/${orderId}`,
{
json:
{
"line_items": [
{
"line_item_id": itemId, "quantity": 1
}
]
}
},
function (error, resp, body) {
if (!error && resp.statusCode == 200) {
console.log(body)
console.log('refund line items transactions information' + JSON.stringify(body.refund.transactions[0]));
console.log('refund line items +++ information THIS IS THE ONE' + JSON.stringify(body.refund.refund_line_items[0]));
refundAmount1 = JSON.stringify(body.refund.refund_line_items[0].price);
order_id1 = body.refund.transactions[0].order_id;
amount1 = body.refund.refund_line_items[0].amount;
// constructing message to front-end with the refund expense.
response = `Your refund amount would be ${refundAmount1}, for the item: ${itemName1}. Do you accept this and wish to initiate the returns process?`
console.log('RESPONSE from getrefundCalc - work to FE?' + response)
data = [details.chatuser, response]
io.of('/main').to(socket.id).emit('response', data);
}
else {
console.log('error' + error)
}
}
)
}
这是我尝试在index.js文件中调用的名称:
console.log('ngrokurl' + ngrokUrl)
console.log('domain' + domain)
console.log('orderId' + orderId)
console.log('itemId' + itemId)
shopifyApiRequest.getRefundCalculationApiCall((itemId, ngrokUrl, domain, orderId));
我的错误:
ngrokurl 2undefined
domain2undefined
orderId2undefined
itemId2594597937215
errorError: Invalid URI "undefined/undefined/undefined"
我期望得到标准答复。我有什么明显的失踪吗?
答案 0 :(得分:1)
在index.js文件中,您正在调用getRefundCalculationApiCall
方法,并在参数周围加上两组括号:
shopifyApiRequest.getRefundCalculationApiCall((itemId, ngrokUrl, domain, orderId));
在参数周围只写上一组括号即可。
shopifyApiRequest.getRefundCalculationApiCall(itemId, ngrokUrl, domain, orderId);
额外的括号将所有四个参数分组为一个,然后将其作为itemId
参数传递。您最终在orderId
语句中打印console.log('itemId2' + itemId)
值。其他三个参数将被忽略,因此未定义。这是一个简单的示例:
function test(arg1, arg2, arg3, arg4) {
console.log('arg1: ' + arg1);
console.log('arg2: ' + arg2);
console.log('arg3: ' + arg3);
console.log('arg4: ' + arg4);
}
console.log('Individual arguments:\n');
test('one', 'two', 'three', 'four');
console.log('Grouped arguments:\n');
test(('one', 'two', 'three', 'four'));