How to use DATAVIEWJS to limit the number of query entries

Things I have tried

What I’m trying to do

Hi, I’m trying to list five projects I’ve worked on recently, and I’m trying to use the limit() function when writing dataviewjs, but it’s reporting an error. I’d like to ask how to fix it and the correct format to write it. :cry: :pray:

Code:

dv.paragraph(
  dv.pages('"05_Projects"').limit(5).file.link.join())

Report:

Evaluation Error: TypeError: dv.pages(…).limit is not a function
at eval (eval at (eval at (app://obsidian.md/app.js:1:1287967)), :2:31)
at DataviewInlineApi.eval (eval at (app://obsidian.md/app.js:1:1287967), :12386:16)
at evalInContext (eval at (app://obsidian.md/app.js:1:1287967), :12387:7)
at DataviewJSRenderer.eval (eval at (app://obsidian.md/app.js:1:1287967), :12877:17)
at Generator.next ()
at eval (eval at (app://obsidian.md/app.js:1:1287967), :26:71)
at new Promise ()
at __awaiter (eval at (app://obsidian.md/app.js:1:1287967), :22:12)
at DataviewJSRenderer.render (eval at (app://obsidian.md/app.js:1:1287967), :12869:16)
at DataviewJSRenderer.eval (eval at (app://obsidian.md/app.js:1:1287967), :12864:28)

Hi.

I’m more versatile in dql, not in js, but I think the issue is:

  • the logic must be “define what you want and, at the end, choose how to see it”;
  • you want the file links (file.links) from the list of pages in your folder “05_Projects”;
  • next, you want to see the results limited to 5 files and join them.
```dataviewjs
dv.paragraph(
  dv.pages('"05_Projects"').file.link.limit(5).join())
```

In your query you define the limit() before what you want (file.link).

Thanks for the reply! I tried putting the limit function after file.link and the error report became

Evaluation Error: TypeError: dv.pages(...).file.link.limit is not a function

I’m not sure what’s going on.

Weird… It works for me.
And, as you can see in documentation, limit() is a function.
And if you use a slice() function?

```dataviewjs
dv.paragraph(
  dv.pages('"05_Projects"').file.link.slice("", 5).join())
```

Is your plugin updated?

2 Likes

Maybe because “file.link” isn’t an array, maybe “file.links”.

Wow, slice() is working!
I confirmed the plugin version is 0.4.5…? I don’t know if it’s a version issue. I’ll update it later and try again.
Thank you very much for your help!

I tried but unfortunately it still didn’t work :cry:
Thank you for your reply!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.