gpt4 book ai didi

javascript - 显示为未定义的参数 - 导出的函数 JavaScript

转载 作者:行者123 更新时间:2023-12-03 01:06:32 26 4
gpt4 key购买 nike

我导出的函数参数值返回为未定义,但我的其他函数以相同的方式工作。希望您能帮忙!

顺便说一句 - 我知道并非所有参数都包含在内,但直到此时它才起作用!

我的函数在 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"

我期待一个标准的回复。我有什么明显的遗漏吗?

最佳答案

在您的 index.js 文件中,您将调用 getRefundCalculationApiCall 方法,并在参数两边加上两组括号:

shopifyApiRequest.getRefundCalculationApiCall((itemId, ngrokUrl, domain, orderId));

这应该只用一组括号括住参数:

shopifyApiRequest.getRefundCalculationApiCall(itemId, ngrokUrl, domain, orderId);

额外的一组括号将所有四个参数组合为一个,然后将其作为 itemId 参数传递。您最终会在 console.log('itemId2' + itemId) 语句中打印 orderId 值。其他三个参数被忽略,因此未定义。这是一个简单的例子:

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'));

关于javascript - 显示为未定义的参数 - 导出的函数 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52379598/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com