我使用这个脚本从多个数组中提取特定的字段:
var values = json.data.flatMap(({ productId, cannabinoidInformation, weightTierInformation }) => cannabinoidInformation.map(({ lowerRange, name }, i) => [productId, lowerRange, name, weightTierInformation[i].name, weightTierInformation[i].gramAmount]));
对于此API:https://flowhub.stoplight.io/docs/public-developer-portal/a377fa23cdec5-inventory-items-by-location
我把剧本修改成:
var values = json.orders.flatMap(({ name, payments,itemsInCart }) => payments.map(({ amount,
paymentType }, i) => [name,amount,
paymentType,itemsInCart[i].quantity, itemsInCart[i].sku]));
我正在尝试使用以下API使其工作:https://flowhub.stoplight.io/docs/public-developer-portal/b41c3d4f8d234-orders-by-location
但我得到这个错误:错误类型错误:无法读取未定义的属性(读取"quantity")
我如何修改上面的脚本来修复我收到的错误消息?
不幸的是,模拟服务器不适用于上面的API,而且由于隐私原因,我不能共享密钥
下面是一个响应示例:
{
"total": 0,
"orders": [
{
"id": "string",
"clientId": "string",
"createdAt": "2019-08-24T14:15:22Z",
"completedOn": "2019-08-24T14:15:22Z",
"customerId": "string",
"currentPoints": 0,
"Name": "string",
"orderStatus": "Pending",
"orderType": "in-store",
"orderId": "string",
"totals": {
"FinalTotal": 0,
"SubTotal": 0,
"TotalDiscounts": 0,
"TotalFees": 0,
"TotalTaxes": 0
},
"itemsInCart": [
{
"id": "string",
"sku": "string",
"category": "BulkBud",
"title1": "string",
"title2": "string",
"productName": "string",
"strainName": "string",
"unitOfWeight": "Each",
"quantity": 0,
"unitPrice": 0,
"totalPrice": 0,
"unitCost": 0,
"totalCost": 0,
"itemDiscounts": [
{
"_id": "string",
"name": "string",
"type": "string",
"discountAmount": 0,
"discountType": "string",
"discountId": "string",
"dollarsOff": 0,
"penniesOff": 0,
"percentOff": 0,
"discounterName": "string",
"discounterId": "string",
"isCartDiscount": true,
"couponCode": "string",
"quantity": 0
}
],
"tax": [
{
"_id": "string",
"name": "string",
"percentage": 0,
"calculateBeforeDiscounts": "string",
"supplierSpecificTax": true,
"excludeCustomerGroups": [
"string"
],
"enableCostMarkup": true,
"markupPercentage": 0,
"thisTaxInPennies": 0,
"appliesTo": "all"
}
]
}
],
"customerType": "recCustomer",
"locationId": "string",
"voided": true,
"fullName": "string",
"budtender": "string",
"payments": [
{
"_id": "string",
"paymentType": "cash",
"amount": 0,
"cardId": "string",
"loyaltyPoints": 0,
"debitProvider": "string",
"balanceAfterPayment": 0
}
]
}
]
}
我想提取以下字段:
1.姓名
1.付款〉付款
1.付款〉付款类型
1.商品购物车〉数量
1.商品购物车〉SKU
1条答案
按热度按时间t40tm48m1#
你需要做的是将
payments
和itemsInCart
Map到包含你需要的信息的更小的数组中。提取name
很简单。试试下面的代码片段,让我知道它是否适合你,或者你是否需要我修改一些东西。