Dataview to dataviewjs - working with inlinks/outlinks of the current note

I have a relatively simple query

TABLE WITHOUT ID 
    notes_root AS "Parent for",
    length(notes_root.parents) AS count,
    "test" AS one_else_col
WHERE file.name = this.file.name
FLATTEN 
    map(
        file.inlinks, 
        (x) => choice(contains(join(x.parents), this.file.name), x, "")) AS notes_root
SORT length(notes_root.parents) DESC

its result

Please tell me - what would the code of the same query look like in dataviewjs?

The main points of the query:

  • Extract inlinks to the CURRENT note
  • working with properties
  • sorting
  • Return table, 1 value = 1 row, with 3+ columns
  • the 2nd column is calculated based on the values (links) from the first

I really tried to look at the dvjs guides myself - and unfortunately the bulk of the examples are based on extracting notes from folders and/or do not return a row-by-row table

P.S.: Why do I want to switch to js? Because the functionality of dataview is sorely lacking in basic things, up to the point of not being able to comment on the code normally

1 Like

I would suggest such a solution:

dv.tableWithoutId(
    dv.notesRoot as "Parent for",
    dv.length(dv.notesRoot.parents) as "count",
    "test" as oneElseCol
)
.where(dv.attr("file").name.eq(this.file.name))
.flatten(
    dv.map(
        dv.attr("file").inlinks,
        (x) => dv.choice(dv.contains(dv.join(x.parents), this.file.name), x, "")
    ),
    dv.alias("notesRoot")
)
.sort(dv.length(dv.attr("notesRoot").parents).desc())

But in general, Dataviewjs does a worse job of analyzing its notes

It is better to reconsider the task and use the Dataview syntax

What did you use to produce this thingy?

Did you try to even execute this? I’ve never seen any dataviewjs resembling something like this.

1 Like