Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataview 实战新文章 #725

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 10-Obsidian/Obsidian社区插件/Dataview/dataview.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ author: Windysoul,Huajin,PKMer
type: other
draft: false
editable: false
modified: 20231209174945
modified: 20240331161350
---

# Obsidian 插件:Dataview
Expand Down Expand Up @@ -133,4 +133,4 @@ Dataview 插件的用途主要有三个方面。
- [[Obsidian样式-可滚动的Dataview表格视图|Dataview实战-给 Dataview 加个滚动条]]
- [[Dataview实战-进度条]]
- [[Dataview语法实战-列出特定标题下的元素]]
-
- [[Dataview实战-展示特定文件夹内未完成任务并且支持子任务图片展示]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
uid: 20240331155510
title: Dataview 实战 - 展示特定文件夹内未完成任务并且支持子任务图片展示
tags: [dataview]
description: 展示特定文件夹内未完成任务并且支持子任务图片展示
author: 是明导么
type: tutorail
draft: false
editable: false
modified: 20240415173301
---

# Dataview 实战 - 展示特定文件夹内未完成任务并且支持子任务图片展示

## 原始 dataview 语句结果如下

```
task
from "测试任务文件夹"
where !completion
```

结果如下。我么发现主任务与子任务的图片都无法正常显示。

![[Dataviewjs 展示特定文件夹内未完成任务并且支持子任务图片展示 1.png]]

## Dataviewjs 语句修改实用方法

将 Dataviewjs 语句中“目标文件夹”替换为你希望检索的文件夹,“附件位置文件夹”替换为你存放附件的文件夹(注:后面的/不要删掉)。完成后你就可以实现 dataview 把 task 列举出来同时支持子任务的图片显示。下图方便理解。

![[Dataviewjs 展示特定文件夹内未完成任务并且支持子任务图片展示 3.png]]

### Dataviewjs 语句结果如下

可以看到 Dataviewjs 语句处理后图片可以正常显示。

![[Dataviewjs 展示特定文件夹内未完成任务并且支持子任务图片展示 2.png]]

#### 代码内容

```dataviewjs语句
let tasks = dv.pages('"测试任务文件夹"').file.tasks
.where(t => !t.completed);
dv.taskList(tasks);

function showPic() {
let imgSpans = document.getElementsByClassName("internal-embed");
for(let i = 0; i < imgSpans.length; i++)
{
let outlinkname = imgSpans[i].innerHTML;
if(outlinkname.endsWith(".jpg")||outlinkname.endsWith(".png")){
let src = app.vault.adapter.getResourcePath("附件/"+outlinkname);
let img = "<img src=\""+src+"\">";
imgSpans[i].innerHTML = img;
}
}
}
setTimeout(showPic, 200)
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.