Skip to content

Conversation

michaelptak
Copy link

Example of using JavaScript to make dynamic Dataview queries in Meta Bind

I made this when normal optionQuery was limited for my use case. Couldn't find a similar example, so it might be a useful starting point for someone else.

@@ -0,0 +1,24 @@
# Making Dynamic Dataview Queries via Meta Bind
A practical example showing how to dynamically populate MetaBind input fields using Dataview queries. This addresses the common use case of wanting to filter suggester options based on note properties, in ways that isn't possible with normal optionQuery. Will require adjustment based on your particular use case, but it's a place to start.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A newline after the heading would be nice


const property = "categories"; // frontmatter property to filter on
const value = "character"; // value to match
// Equivalent to the Dataview query WHERE categories = "character"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you say categories equals character


// Query notes where the property contains the value
const pages = dv.pages()
.where(p => p[property] && p[property].includes(value));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But here you write value in property

# Making Dynamic Dataview Queries via Meta Bind
A practical example showing how to dynamically populate MetaBind input fields using Dataview queries. This addresses the common use case of wanting to filter suggester options based on note properties, in ways that isn't possible with normal optionQuery. Will require adjustment based on your particular use case, but it's a place to start.

The code block here is the equivalent of making the query `WHERE {property} = "{value}"`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence here is confusing.

Hopefully much better clarity now
@michaelptak
Copy link
Author

I hopefully clarified the field name usage, and provided a much better example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants