1 回答
TA贡献1757条经验 获得超8个赞
我不确定您的记录的确切数据结构是什么。但我认为您可以使用动态键名:
function getPoints(records, dropdownValue) {
return records.map((item) => {
let mapedItem = {};
for (const key in item) {
if (key.indexOf(`${dropdownValue}_lot`) !== -1) {
mapedItem[key] = item[key];
}
}
mapedItem["id"] = item["id"];
mapedItem["sector_name"] = item["sector_name"];
return mapedItem;
});
}
const data = [
{
id: 1,
sector_name: 2,
f_day_lot1: "f_day_lot1",
f_day_lot2: "f_day_lot2",
f_day_lot3: "f_day_lot3",
f_day_lot4: "f_day_lot4",
f_month_lot1: "f_month_lot1",
f_month_lot2: "f_month_lot2",
f_month_lot3: "f_month_lot3",
f_month_lot4: "f_month_lot4",
f_week_lot1: "f_week_lot1",
f_week_lot2: "f_week_lot2",
f_week_lot3: "f_week_lot3",
f_week_lot4: "f_week_lot4"
}
];
console.log(getPoints(data, "day"));
console.log(getPoints(data, "week"));
console.log(getPoints(data, "month"));
添加回答
举报