【已解决】dataview输出带有标签的文件链接的代码是否可以包含多个标签?

有一种 输出所有带有标签的文件链接以及对应行且形成表格 的代码

```dataviewjs
// 获取 Obsidian 中的所有 Markdown 文件
const files = app.vault.getMarkdownFiles()

// 将带有标签的文件以及行筛选出来
let arr = files.map(async(file) => {
  const content = await app.vault.cachedRead(file)
//turn all the content into an array
let lines = await content.split("\n").filter(line => line.includes("#tag"))
return ["[["+file.name.split(".")[0]+"]]", lines]
})

// 生成表格,如果要将当前的文件排除的话,请修改其中的排除文件
Promise.all(arr).then(values => {
console.log(values)
//filter out files without "Happy" and the note with the dataview script
const exists = values.filter(value => value[1][0] && value[0] != "[[排除文件]]")
dv.table(["file", "lines"], exists)
})
​```

问题:原始代码只能输出一种标签,本人不太懂代码,能不能帮忙改造以下,可以直接一起输出两种或者多种标签,然后按标签排列成表格,非常感谢!

1 个赞

对代码稍做修改可以包含多个 标签,前提是每个标签都得自己手动添加,这样可以么?

```dataviewjs
// 获取 Obsidian 中的所有 Markdown 文件
const files = app.vault.getMarkdownFiles()

// 将带有标签的文件以及行筛选出来
let arr = files.map(async (file) => {
    const content = await app.vault.cachedRead(file)

    //turn all the content into an array
    let lines = await content.split("\n").filter(line => {
        return (

            line.includes("#灵感") ||
            line.includes("#49") ||
           // 上面一行代码 `line.includes("#49") ||` 复制这里就行,再改以下标签名称就行。   


           // 代码这粘贴到这里。


            line.includes("#思维工具")
        )
    }

    )
    return ["[[" + file.name.split(".")[0] + "]]", lines]
})

// 生成表格,如果要将当前的文件排除的话,请修改其中的排除文件
Promise.all(arr).then(values => {
    console.log(values)
    //filter out files without "Happy" and the note with the dataview script
    const exists = values.filter(value => value[1][0] && value[0] != "[[排除文件]]")
    dv.table(["file", "lines"], exists)
})
2 个赞

显示下列错误:
Evaluation Error: SyntaxError: Unexpected token ‘)’
at DataviewInlineApi.eval (eval at (app://obsidian.md/app.js:1:1278841), :12947:21)
at evalInContext (eval at (app://obsidian.md/app.js:1:1278841), :12948:7)
at eval (eval at (app://obsidian.md/app.js:1:1278841), :12956:20)
at Generator.next ()
at eval (eval at (app://obsidian.md/app.js:1:1278841), :42:71)
at new Promise ()
at __awaiter (eval at (app://obsidian.md/app.js:1:1278841), :38:12)
at asyncEvalInContext (eval at (app://obsidian.md/app.js:1:1278841), :12954:12)
at DataviewJSRenderer.eval (eval at (app://obsidian.md/app.js:1:1278841), :13484:23)
at Generator.next ()

以纯文本形式粘贴 的么?

有时候还好使。我再调试一下,感谢

已经调试成功了,非常感谢!

1 个赞

在使用过程中,又产生了一个需求,有#a1,#a2#a3这三个标签,搜索内容能否按照#a1,#a2#a3,。。。。。#aN这样的标签排序

这个俺家不会写了。

好的,还是非常感谢你

请问这段代码里面能不能加个排序?我的文件是
2022-01-01.md
2022-01-02.md
现在是乱序的,想要按时间排序(正序或倒序,两种都有需要最好能告诉我正序和倒序分别是什么代码)感谢

同问,我的错误也是这个