【发布时间】:2019-11-26 14:29:18
【问题描述】:
我无法映射阵列的击球手部分。作业要求:“击球手”:“所有击球手类型为字符串。如果没有多个数组,我无法映射它。目标是让击球手显示,例如
面糊:“普通”、“巧克力”、“蓝莓”
我已经尝试过数组的 .join 方法必须显示为字符串,不断出错。
sabio.page.startUp = function () {
console.log(oldCakesObject);
let newCakes = oldCakesObject.items.item.map(sabio.page.mapCakes);
console.log(newCakes);
}
sabio.page.mapCakes = function (cake) {
let numberOfFillings = 0;
let batters = batter.join()
if (cake.fillings) {
numberOfFillings = cake.fillings.filling.length
}
return {
id: cake.id,
type: cake.type,
name: cake.name,
ppu: cake.ppu,
// batters: cake.items.batter,
ingredients: cake.topping,
countOfFillings: numberOfFillings
}
};
{
"items":
{
"item":
[
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
我在尝试 console.log 击球手时遇到错误。唯一的问题是击球手。
【问题讨论】:
标签: javascript html arrays mapping filtering