跳到主要内容

GetItem

返回集合中指定位置的目录。

备注

此功能仅在 ONLYOFFICE Docs 付费版本中可用。

语法​

expression.GetItem(nIndex);

expression - 表示 ApiTablesOfContents 类的变量。

参数​

名称必需/可选数据类型默认值描述
nIndex必需number目录的位置(从零开始)。

返回值​

ApiTableOfContents | null

示例​

按索引从文档集合中获取目录。

// Add a table of contents built from the document headings to the collection.

// Retrieve the first table of contents from the collection by its zero-based index.

let doc = Api.GetDocument();
let style = doc.GetStyle("Heading 1");
let paragraph = doc.GetElement(0);
paragraph.SetStyle(style);
paragraph.AddText("Chapter 1");
let tablesOfContents = doc.GetTablesOfContents();
tablesOfContents.Add({"BuildFrom": {"OutlineLvls": 9}});
let toc = tablesOfContents.GetItem(0);
let resultParagraph = Api.CreateParagraph();
resultParagraph.AddText("Item class type: " + toc.GetClassType());
doc.Push(resultParagraph);