But that didn’t work so I tried to declare status as a variable, after dv.header and before dv.list:
const status = k.status;
Then I performed the “forEach” function:
status.forEach(VI);
And finally modified the “map” line as following:
.map(k => k.symbol + " " + k.file.link + " :luc_arrow_big_left: " + function VI(item) { if (item == "Manufacturing") {"🏗️"} else if (item == "Active") {"🟢"} else if (item == "Idle") {"🔴"} else {item} })
That didn’t work either.
What I’m trying to do
As mentioned in the title I want to write an “if statement” in “map” function of a dataviewjs block to have the same result of “choice” in dataview blocks. I’m new to learning Javascript, but I’m still not able to work this out.
Well, I’m a JS dumb (as in code in general)… because that take as “fragile” my observations about this subject.
But I suggest you solve that before the group step. For example:
const pages = dv.pages('"2 - Pillars"')
.where(p => p.file.name != dv.current().file.name)
for (let page of pages){
if (page.status == "Manufacturing"){
page.status = "🏗️"
} else if (page.status == "Active"){
page.status = "🟢"
} else if (page.status == "Idle"){
page.status = "🔴"
}
}
for (let group of pages.groupBy(p => p.class)){
dv.header(2, group.key);
dv.list(
group.rows
.sort(k => k.order, 'ASC')
.map(k => k.symbol + " " + k.file.link + " 🪴 " + k.status)
)
}
I started learning JavaScript just to solve this specific problem, and I was still clueless after 39 lessons from some course. I really appreciate your help.