跳至主要内容

indentTask()

描述

根据相邻任务将该任务的嵌套级别降低一级

用法

indentTask({
id: string | number
}): void;

参数

  • id - (必填)任务的 id

示例

示例 1. 降低单个任务的嵌套级别
const { ToDo, Toolbar } = todo;

const list = new ToDo("#root", {
tasks: [
{ id: "1", text: "Task 1 #tag1" },
{ id: "1.1", text: "Task 1.1", parent: "1" },
{ id: "1.1.1", text: "Task 1.1.1", parent: "1.1" },
{ id: "1.2", text: "Task 1.2", parent: "1" },
]
});

const toolbar = new Toolbar("#toolbar", {
api: list.api,
});

// 降低该任务的嵌套级别
list.indentTask({
id: "1.2",
});

console.log(list.getParentIds({ id: "1.2" })); // ['1.1', '1']
示例 2. 降低多个任务的嵌套级别
const list = new ToDo("#root", {
tasks: [
{ id: "1", text: "Task 1" },
{ id: "1.1", text: "Task 1.1"},
{ id: "1.1.1", text: "Task 1.1.1", parent: "1.1" },
{ id: "1.2", text: "Task 1.2", parent: "1" },
{ id: "2", text: "Task 2" },
{ id: "2.1", text: "Task 2.1", parent: "2" },
{ id: "2.1.1", text: "Task 2.1.1", parent: "2.1" },
{ id: "2.2", text: "Task 2.2" },
],
selected: ["1.1", "2.2"],
});

// 降低所选任务的嵌套级别
list.eachSelected(id => {
list.indentTask({ id });
}, true);

相关文章: