DataviewJS formatting issue

I’m using a DataviewJS block to gather ingredients from recipe notes:

for (let entry of dv.pages('"_Resources/Ingredients"').where(p => p.type == "ingredient")
    .groupBy(p => p.category)) {
    dv.header(2, entry.key);
    dv.list(entry.rows.sort(p => p.file.name).map(p => [p.file.link]))
}

It works great, but is displaying each list item with two bullet icons:
Screenshot 2023-02-23 184703

Any idea why it’s doing that and how do I make it stop? I switched to a few different themes and they didn’t make a difference. I also tried moving the Ingredients folder to the root but it still shows two bullets.

You’re display a list of lists, which you inadvertently created when doing .map(p = [ p.file.link ] ). Simplify that, and you’re good to go:

```dataviewjs
for (let entry of dv.pages('"_Resources/Ingredients"').where(p => p.type == "ingredient")
    .groupBy(p => p.category)) {
    dv.header(2, entry.key);
    dv.list(entry.rows.sort(p => p.file.name).map(p => p.file.link))
}
```

That is the only change needed to get it working, but whilst working with this I reformatted the query, and personally I find it easier to read in this form:

```dataviewjs
const entries = dv.pages('"_Resources/Ingredients"')
  .where(p => p.type == "ingredient")
  .groupBy(p => p.category)

for (let entry of entries) {
    dv.header(2, entry.key);
    dv.list(entry.rows
              .sort(p => p.file.name)
              .map(p => p.file.link)
    )
}
```

I thinks this format is easier on the eye, and it’s easier to read what’s happening without all that side scrolling. But that’s a personal preference.

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

Just tried your suggestion and it works perfectly. I do also prefer your suggested layout, helps me to better understand what’s going on and is more comparable to other languages I semi-know (I copy/pasted the code I was using from a forum post). I’m still early in learning this language! Thanks also for the tip on pasting code in the forum, I struggled with that!

1 Like

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