For my movie database, I’ve got notes for actors and notes for movies.
In the movie-note I mention all actors in a particular movie in YAML, using the list-property.
In the actor-note I’ve got a dataviewjsquery set up, where (per movie) I show title, publication date and actors.
I would like to exclude the current actor from the list and then show “plays with … {rest of array}”
The current query is this:
dv.table(["Icon", "Poster", "Title", "Actors", "Date of Publication"], dv.pages('"Movies"')
.where(p => dv.func.contains(p.actors, dv.current().file.link))
.map(p => [
p.Icon,
p.posterLink,
dv.fileLink(p.file.path, false, p.title),
p.actors,
p.date_publication
])
);
I’ve tried using p.actors.filter(a => a.actors !== dv.current().file.link
, but then it still shows the current actor. I’ve checked actors
via typeof
and it’s an array.
I know I can get the first mentioned actor via actors[0]
, but how can I exclude dv.current().file.link
from this array?
holroy
December 23, 2024, 8:43pm
2
You said p.actors.filter(a => a.actors !== dv.current().file.link)
, but here you’re looking at each actors
internal field actors
… Is that present?
Shouldn’t this be: p.actors.filter(a => a !== dv.current().file.link)
?
Hi @holroy , you’re probably right, since there’s no actors
-field inside actors
.
I’ve tried using your suggestion, but unfortunately this still shows the current actor
(aka current file name/link).
Dave_PR
December 30, 2024, 10:21am
4
Have you tried p.actors.filter(a => a.path !== dv.current().file.link.path)
I had to do something similar and the below filters out the current page from the connections property
dv.table(["File", "Other connections"],
dv.pages("-#kb-article")
.where(p => dv.func.contains(p.connections, dv.current().file.link))
.map(b => [b.file.link, b.connections.filter(p =>
p.path !== dv.current().file.link.path
)])
)
holroy
December 30, 2024, 10:37am
5
There was something not right in my previous post, and the post by @Dave_PR further enhanced this feeling. Then I remembered that you can’t compare links directly in dataviewjs , you need to use the .equals()
function. (Or compare a subpart like the file.path
)
You can’t just compare links like that. Try the following in a file of its own:
[[Something]]
[[Something|someone]]
```dataviewjs
const outlinks = dv.current().file.outlinks
dv.paragraph(outlinks)
dv.paragraph("object vs object: " + (outlinks[0] == outlinks[1]) )
dv.paragraph("link.equals(): " + outlinks[0].equals(outlinks[1]))
```
So in your case it should suffice to do saved1.equals(saved2).
So try using p.actors.filter(a => !a.equals(dv.current().file.link))
1 Like