Dataviewjs gives a listed number when a number is accessed from outside

Things I have tried

I have a file with a format like this.

  - books
title: Moonlight
totalpages: 534

In the current file,

const bookpages = dv.current().totalpages


This gives a number.


But, when I tried to access the totalpages from the other file using

const bookpages = dv.pages().where(p => p.title == 'Moonlight').totalpages


This gives a listed number.

  • 534

What I’m trying to do

I’d like to get a number not a listed number when I access the totalpages from outside file.

The query you’ve been using could potentially be referring to multiple files having the title “Moonlight”, and field totalpage, so it presents the result as a list. Albeit with only one item, but still a still a list.

So I’d rather try something like:

const bookpages ='Moonlight').totalpages

dv.paragraph( bookpages )

It works great. Thank you.

One question.
I have tested by changing the File Name and the yaml field - title.
It looks like that‘Moonlight’) seems to refer to the “File Name”.
Is there any method to refer to the yaml field with

It do refer to the file name. If you want it to refer to the yaml field, you’ll also need to do some other magic to avoid the list case. Like selecting only the first entry in the list, limiting to one result, or similar stuff.

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