Skip to content

Properties 高级用法

Properties(属性)是 Obsidian 1.4.0 引入的功能,用于为笔记添加结构化元数据。本文介绍高级用法和技巧。

版本要求

Properties 功能需要 Obsidian 1.4.0 及以上版本。

快速回顾

基本语法

yaml
---
title: 笔记标题
date: 2024-02-15
tags: [标签1, 标签2]
status: active
---

支持的数据类型

类型示例用途
Texttitle: 标题文本内容
Listtags: [a, b, c]标签、分类
Numberpriority: 1优先级、评分
Checkboxpublished: true布尔值
Datedue: 2024-02-20日期
DateTimecreated: 2024-02-15T10:30日期时间
Aliasaliases: [别名1]笔记别名
Linkproject: "[[Project]]"链接

高级技巧

1. 嵌套属性

使用缩进创建嵌套结构:

yaml
---
title: 项目文档
meta:
  author: 张三
  version: 1.0
  updated: 2024-02-15
---

2. 多行文本

使用 | 保留换行:

yaml
---
title: 笔记
summary: |
  这是第一行摘要。
  这是第二行摘要。
  可以包含多行内容。
---

3. 默认值模板

创建包含默认属性的模板:

templates/note.md

yaml
---
title: "{{title}}"
created: "{{date}}"
modified: "{{date}}"
tags: []
status: draft
type: note
---

# {{title}}

## 内容

## 相关链接

4. 属性继承

通过链接实现属性"继承":

yaml
---
# project.md
name: 项目A
deadline: 2024-03-01
team: [张三, 李四]
---

---
# task.md
project: "[[项目A]]"
---

使用 Dataview 查询关联属性:

dataview
TABLE project.name as "项目", project.deadline as "截止日期"
FROM "Tasks"
WHERE project

与插件联动

Dataview 查询

dataview
TABLE status as "状态", date as "创建日期", priority as "优先级"
FROM "Projects"
WHERE status = "active"
SORT priority DESC

Tasks 插件

在属性中定义任务信息:

yaml
---
due: 2024-02-20
priority: high
completed: false
tags: [task, urgent]
---

Templater 自动化

自动填充属性:

javascript
<%*
// 自动设置创建时间
const created = tp.file.creation_date("YYYY-MM-DD");
const modified = tp.file.last_modified_date("YYYY-MM-DD");

tR += `---
created: ${created}
modified: ${modified}
---`;
%>

属性管理最佳实践

命名规范

yaml
# ✅ 推荐:使用一致的命名
created_date: 2024-02-15
modified_date: 2024-02-20
due_date: 2024-02-25

# ❌ 不推荐:命名不一致
created: 2024-02-15
date_modified: 2024-02-20
deadline: 2024-02-25

常用属性标准

属性名类型用途
titletext笔记标题
aliaseslist别名
tagslist标签
createddate创建日期
modifieddate修改日期
statustext状态 (draft/review/done)
prioritynumber优先级 (1-5)
typetext类型 (note/project/task)

状态管理

定义标准状态值:

yaml
# 文档状态
status: [draft, review, published, archived]

# 任务状态
status: [todo, in-progress, done, cancelled]

# 项目状态
status: [planning, active, on-hold, completed]

Bases 与 Properties 结合

版本要求

Bases 功能需要 Obsidian 1.7.2 及以上版本。

创建数据库视图

  1. 创建一个 bases 文件夹
  2. 新建 .base 文件

projects.base

yaml
type: base
sources:
  - path: Projects/
    properties:
      - name: title
        type: text
      - name: status
        type: select
        options: [active, completed, on-hold]
      - name: deadline
        type: date
      - name: team
        type: list

数据库查询

在笔记中嵌入 Bases 视图:

markdown
```base
from: Projects/
where: status = "active"
sort: deadline asc
columns: [title, status, deadline, team]

## 实用示例

### 任务管理

```yaml
---
type: task
title: 完成报告
project: "[[项目A]]"
assignee: 张三
due: 2024-02-20
priority: 3
status: in-progress
tags: [work, urgent]
---

## 任务描述

## 子任务
- [ ] 收集数据
- [ ] 分析结果
- [ ] 撰写报告

## 进度记录

阅读笔记

yaml
---
type: reading
title: 书名
author: 作者名
isbn: 978-xxx
rating: 4
start_date: 2024-02-01
end_date: 2024-02-15
status: completed
tags: [book, non-fiction]
---

## 摘要

## 精彩段落

## 我的思考

会议记录

yaml
---
type: meeting
title: 项目启动会
date: 2024-02-15
time: 14:00-15:30
location: 会议室A
attendees: [张三, 李四, 王五]
project: "[[项目A]]"
tags: [meeting, project]
---

## 议程

## 讨论内容

## 行动项
- [ ] 张三:准备技术方案
- [ ] 李四:完成市场调研

属性迁移

从旧格式迁移

如果你的笔记使用旧的 Front Matter 格式:

javascript
// 使用 Templater 批量更新
<%*
const files = app.vault.getMarkdownFiles();
for (const file of files) {
  const content = await app.vault.read(file);
  const frontmatter = app.metadataCache.getFileCache(file)?.frontmatter;
  
  if (frontmatter && frontmatter.date) {
    // 更新属性名
    const newContent = content.replace(
      /^date:/m, 
      'created:'
    );
    await app.vault.modify(file, newContent);
  }
}
%>

常见问题

问:属性中文无法正常显示?

答:确保文件编码为 UTF-8,YAML 支持中文属性名和值。

问:如何批量修改属性?

答:可以使用:

  1. Templater 脚本批量处理
  2. "Metadata Menu" 插件
  3. 直接编辑 .obsidian/app.json

问:属性和标签有什么区别?

答:

  • 标签:用于分类和筛选
  • 属性:用于结构化数据和查询

相关资源

最后更新:2026年3月28日编辑此页反馈问题