dataview
文档外使用 dv
const dv=app.plugins.plugins.dataview.api
或
const dv=DataviewAPI
dv.el 嵌套
dv.el('div', dv.el('span', 'demo'))
dv.el('ul', dv.el('li', dv.el('span', 'demo')));
dv.query
```dataviewjs
const result = await dv.query(`list`)
if (result.successful) {
const list = result.value.values
console.log(list)
} else {
dv.paragraph("~~~~\n" + (result.error||"未知错误") + "\n~~~~")
}
```
最近修改文件
```dataviewjs
dv.list(
dv.pages()
//.filter(p => moment(p.file.mday.toString()).format('MD') === moment().format('MD'))
.sort(p => p.file.mtime, 'desc')
.limit(100)
.map(p => {
const a=dv.el('a', p.file.name, { attr: { "data-href": p.file.path } });
a.addEventListener('click', function(e) {
app.workspace.getLeaf('tab').openFile(app.vault.getAbstractFileByPath(this.getAttribute("data-href")));
});
return a;
})
)
```
特殊语法 ::
示例:
a::aa1
a::aa2
b::b1
b::b2
读取 app.plugins.plugins.dataview.api.page("demo.md")
返回:
{
"a": [
"aa",
"aa1"
],
"b": [
"b1",
"b2"
]
}
js 执行命令
this.app.commands.executeCommandById('app:open-settings')
查看命令列表
this.app.commands.listCommands()