正在将映射函数导出到其他文件中



是否可以导出orders.map中的函数"order",并将其导入到其他包含函数的JS文件中?我收到一个未定义的错误顺序。谢谢

main.js
const getReport = async function() {
const jsonlUrl = 'https://next.json-generator.com/api/json/get/xxxxx'
const res = await fetch(jsonlUrl);
const orders = await res.json();
const orderlines = orders.map(order => ({
order_id: order.order_id,
customer_name: getName()
}));
---
function.js
const getName = function() {
const customerName = order.customer_name
return customerName
}

已解决:将参数传递到函数调用

main.js
const getReport = async function() {
const jsonlUrl = 'https://next.json-generator.com/api/json/get/xxxxx'
const res = await fetch(jsonlUrl);
const orders = await res.json();
const orderlines = orders.map(order => ({
order_id: order.order_id,
customer_name: getName(order)
}));

我在函数getName 上添加了参数

function.js
const getName = function(order) { 
const customerName = order.customer_name 
return customerName 
} 

最新更新