【发布时间】:2020-04-26 12:20:54
【问题描述】:
是否可以将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
}
【问题讨论】:
-
什么是“其他 JS 文件”?不清楚。
-
你好@jhenderson2099,我已经更新了代码。谢谢
-
已解决。我做了``` function.js const getName = function(order) { const customerName = order.customer_name return customerName } ``
标签: javascript node.js ecmascript-6 ecmascript-5