Page structure
frontmatter has property up which is an array that contains links to other pages Objective
With dataviewjs, get all the tasks that
have a status i
are on page for which the current page is included in the “up” property
Things I have tried
Lots of google trying to figure this out, separately visualing the variables
dv.table(["File", "Task", "Up"],
dv.pages("#log and (\"Journal\" or \"Notes\" or \"Private\")")
.flatMap(p => p.file.tasks.map(t => ({
...t,
file: p.file,
up: p.file.frontmatter.up
})))
.filter(t =>
t.up &&
t.up.includes(dv.current().file) &&
t.status === "i"
)
.sort(t => t.file.ctime, 'desc')
.map(t => [
t.file.link,
t.text,
t.up
])
)```
The part that is failing is this line
t.up.includes(dv.current().file)
as it never is true. I have tried file, file.name, file.link
As a test - removing that line, up will show an array of links including the link of current page
If I display dv.current().file.link I see the current file link.
Appreciate any help - I feel I am not using includes properly in this case
I’m not sure I follow all of your setup, but to compare links you need to use .equals(), and furthermore to check against a list you need to check for equality on each of the links.
Thanks, I remember seeing “some” before but didn’t make the connection
I entered your suggestion and run into this error Evaluation Error: TypeError: s.equals is not a function
Eh… Then it doesn’t recognise it as a link, and that is because you earlier forced it to be the raw value by doing up: p.file.frontmatter.up. Change that to simply up: p.up, and you’ll see it works like expected.
Thanks @holroy that worked like a charm
Pretty difficult to figure out by myself, so it looks like both those are not equivalent (obviosuly your work )
Trying to understand the difference, when I do below $=dv.current().up $=dv.current().file.frontmatter.up
Observations
The output is exactly the same
They are both typeof = object
They both seem like an array and allow to query with [0]
Take a look at them in the developer tools, and they should different.
I never use file.frontmatter unless I explicitly dumt want Dataview to apply any logic. I.e. if you got a value of 5mdataview understands it as a duration of 5 minutes, but to me it most often means 5 meter. Then I need to use the file.frontmatter variant to get the 5 out of it.
Similar cases exists related to some link usage, and more esoteric string handling.
Thanks I was able to see this on the console and explore a little. I have a better understanding of the data sctructures now
I can see the frontmatter up element contains an array of text. The page up element contains an array of link. They are not the same