Dataviewjs array and includes

What I’m trying to do

Page structure
frontmatter has property up which is an array that contains links to other pages
Objective
With dataviewjs, get all the tasks that

  1. have a status i
  2. 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.

So this untested, but something like:

t.up.some(s => s.equals(dv.current().file.link))

Thanks, I remember seeing “some” before but didn’t make the connection
I entered your suggestion and run into this error :anguished:
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.

At least it does work in my tests.

1 Like

Thanks @holroy that worked like a charm :+1:
Pretty difficult to figure out by myself, so it looks like both those are not equivalent (obviosuly your work :grinning:)
Trying to understand the difference, when I do below
$=dv.current().up
$=dv.current().file.frontmatter.up
Observations

  1. The output is exactly the same
  2. They are both typeof = object
  3. They both seem like an array and allow to query with [0]
    :person_shrugging:

What does it mean one is raw value?

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 5m dataview 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

1 Like