跳至主要内容

项目对象

获取项目对象

要获取项目对象,请使用 getProject() 方法。以下示例通过 id 检索项目:

const projects = [
{ id: "first", label: "First project" },
{ id: "second", label: "Second project" },
{ id: "third", label: "Third project" },
];

const list = new ToDo("#root", { projects });

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

list.getProject({ id: "first" }); // -> {id: 'first', label: 'First project'}

检查项目是否存在

要检查某个项目是否存在,请使用 existsProject() 方法。以下代码片段检查两个 id:

const projects = [
{ id: "first", label: "First project" },
{ id: "second", label: "Second project" },
{ id: "third", label: "Third project" },
];

const list = new ToDo("#root", { projects });

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

list.existsProject({ id: 1 }); // -> false
list.existsProject({ id: "first" }); // -> true