【求助】如何使用 dataview 插件过滤出某个二级标题下的内容

我的每篇日记里都有一个二级标题 ”## 任务“,请问我怎么使用 dataview 把这个二级标题下的所有内容过滤出来?谢谢!:slightly_smiling_face: :smiley:

不知道如何用dataview。
但是用这个插件可以达到你说的目的。
在设置中把标签更改为## 任务就可以了。

1 个赞

任务里面都是待办事项吧,你也可以看看这个教程。

1 个赞

代码如下

```dataview
task
where meta(section).subpath = "1-6级标题名称"
```
2 个赞

谢谢你的回复。请问我想获取标题下的所有内容(内容不仅是待办事项),这个代码怎么写? :smiley:

请问解决了吗,我也有这个需求

汇总【指定小标题下的全部内容】,包括task、普通文本等

```dataviewjs
//输入目标小标题(含#),例如:#### 项目进度条
const header = '#### 项目进度条'

// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
const pages = dv.pages('"00数据管理" or ""').filter(p => p.file.name.includes("") && !p.file.path.includes("template")).filter(p => p.file.name.includes("") || p.file.name.includes("")).sort(p=>p.file.mtime,"desc");

// This regex will return text from the Summary header, until it reaches
// the next header, a horizontal line, or the end of the file
const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    // Extract the summary via regex
    const summary = contents.match(regex)
    //显示全部包括空结果if (summary) {
    //不显示空结果if (summary && summary[1].trim()) {
    if (summary && summary[1].trim()) {
        // Output the header and summary
        dv.header(2, page.file.link)
        //或者dv.header(2, '[[' + file.basename + ']]')
        dv.paragraph(summary[1].trim())
    }
}
```