我导出的函数参数值返回为undefined,我的其他函数以相同的方式工作。希望你能帮忙!
顺便说一下 - 我知道并不是所有的参数都包括在内,但直到这一点它还没有工作!
我的函数在我的帖子Requests.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"
我期待一个标准的回应。我有什么明显缺失的吗?
在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'));