Public
Edited
Aug 18, 2023
Insert cell
Insert cell
today = new Date()
Insert cell
day = today.getDay()
Insert cell
today.getTime()
Insert cell
function getDate(i) {
const date = new Date(today.getTime() + (i - day) * 1000 * 60 * 60 * 24);
return String(date.getMonth() + 1).padStart(2, '0') + '-' + String(date.getDate()).padStart(2, '0')
}
Insert cell
getDate(1)
Insert cell
{
return {
title: '周一 ' + getDate(1),
dataIndex: 'monday',
}
}
Insert cell
data = [
{
date: "2023-08-11",
period: {
morning: ["李四"],
afternoon: ["张隽丹"]
}
},
{
date: "2023-08-12",
period: {
afternoon: ["张隽丹", "李四"]
}
}
]
Insert cell
{
let res = [{
key: '1',
period: '上午',
},
{
key: '2',
period: '下午',
},];

data.forEach((item) => {
if (Object.hasOwn(item.period, "morning")) {
res[0][item.date] = item.period.morning;
}

if (Object.hasOwn(item.period, "afternoon")) {
res[1][item.date] = item.period.afternoon;
}
});

return res;
}
Insert cell
{
let res = [];
data.forEach((item) => {
if (Object.prototype.hasOwnProperty.call(item.period, 'morning')) {
item.period.morning.forEach((doctorName) => {
res.push({name: doctorName})

res[res.length-1][item.date] = "上午"
})
}

if (Object.prototype.hasOwnProperty.call(item.period, 'afternoon')) {
item.period.afternoon.forEach((doctorName) => {
res.push({name: doctorName})

res[res.length-1][item.date] += "下午"
})
}
});

return res;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more