Datacore: How to return list-items or tasks?

I’m trying datacore. I don’t know JavaScript or react, so I’m hacking.

I can’t find any code examples for returning a list of list items or tasks. Only returning pages.

Return pages example

E.g. All notes containing “#s”:

```datacorejsx
return function View() {
    const pages = dc.useQuery('@page and #s');
    return <dc.List rows={pages} renderer={pages => pages.$link} />;
}
```

…works perfectly. And it’s such simple code, I had high hopes that I could just swap out a term or two…

Return list-items or tasks, how?

But if I replace @page with other types (@list-item or @task) then I get a list of double bullet points, with no visible text or links. It’s about the right length of list though.

What I tried

I tried modifying the “pages” in “const pages” to list-item, list-items, task, tasks, data: all caused an error.

Similarly I tried modifying each of the “pages” in “return <dc.List rows={pages} renderer={pages => pages.$link}” but got more errors.

I’d appreciate any hints or working code examples – thanks.

1 Like

From Datacore’s queries and list views descriptions, it seems that this is one way to return the lists items from all notes tagged #s:

return function View() {
	const items = dc.useQuery('@list-item and childof(@page and #s)');
	return <dc.List rows={items} />;
}

Forum posts about Datacore get little traction as of yet, but your question got me to finally take a look at the docs. I’ve not used Datacore, don’t know JavaScript, and am happy to be schooled about any known better practices than this one.

1 Like

Unlike page, list-item has no $link property, that is why you are getting list of empty items. You could just remove renderer i.e. return <dc.List rows={pages} />; to make it work.

1 Like

Thanks, I’ve tried those. They aren’t working yet, though.

dawni:
That seems to display all list items on pages that contain the tag. (But it’s progress.)

pkb:
Each result in the list is identical and looks like this:
• <_MarkdownPage>

I was assuming you would replace @page with @list-item in the query.
i.e:

return function View() {
    const items = dc.useQuery('@list-item and #s');
    return <dc.List rows={items}  />;
}
2 Likes

Code by @dawni works too, but it queries list items from pages having tag #s not list items tagged with #s, don’t know what your intent is.

This would be just the items that contain the tag, if that’s your intent:

const items = dc.useQuery('@list-item and #s');

I thought you wanted working examples, but if there’s an(other) exact result you want help with, then can you be more specific?