OneNote.PageCollection class

表示页面的集合。

Extends

注解

[ API 集:OneNoteApi 1.1 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

count

返回集合中页面的数目。 只读。

items

获取此集合中已加载的子项。

方法

getByTitle(title)

获取具有指定标题的页面集合。

getItem(index)

按其在集合中的 ID 或索引获取页面。 只读。

getItemAt(index)

按其在集合中的位置获取页面。

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来,调用toJSON传递给它的 对象的 方法。) 虽然原始OneNote.PageCollection对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 OneNote.Interfaces.PageCollectionData) ,其中包含一个“items”数组,其中包含集合项中任何已加载属性的浅表副本。

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 的 context.trackedObjects.add(thisObject)简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在对对象设置属性或调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪的对象集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 的 context.trackedObjects.remove(thisObject)简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

count

返回集合中页面的数目。 只读。

readonly count: number;

属性值

number

注解

[ API 集:OneNoteApi 1.1 ]

items

获取此集合中已加载的子项。

readonly items: OneNote.Page[];

属性值

方法详细信息

getByTitle(title)

获取具有指定标题的页面集合。

getByTitle(title: string): OneNote.PageCollection;

参数

title

string

页面的标题。

返回

注解

[ API 集:OneNoteApi 1.1 ]

示例

await OneNote.run(async (context) => {

    // Get all the pages in the current section.
    const allPages = context.application.getActiveSection().pages;

    // Queue a command to load the pages.
    // For best performance, request specific properties.
    allPages.load("id"); 

    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();

    // Get the sections with the specified name.
    const todoPages = allPages.getByTitle("Todo list");

    // Queue a command to load the section.
    // For best performance, request specific properties.
    todoPages.load("id,title"); 

    await context.sync()

    // Iterate through the collection or access items individually by index.
    if (todoPages.items.length > 0) {
        console.log("Page title: " + todoPages.items[0].title);
        console.log("Page ID: " + todoPages.items[0].id);
    }
});

getItem(index)

按其在集合中的 ID 或索引获取页面。 只读。

getItem(index: number | string): OneNote.Page;

参数

index

number | string

页面的 ID 或集合中页面的索引位置。

返回

注解

[ API 集:OneNoteApi 1.1 ]

getItemAt(index)

按其在集合中的位置获取页面。

getItemAt(index: number): OneNote.Page;

参数

index

number

要检索的对象的索引值。 从零开始编制索引。

返回

注解

[ API 集:OneNoteApi 1.1 ]

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(options?: OneNote.Interfaces.PageCollectionLoadOptions & OneNote.Interfaces.CollectionLoadOptions): OneNote.PageCollection;

参数

options

OneNote.Interfaces.PageCollectionLoadOptions & OneNote.Interfaces.CollectionLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames?: string | string[]): OneNote.PageCollection;

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

示例

await OneNote.run(async (context) => {
    
    // Get the pages in the current section.
    const pages = context.application.getActiveSection().pages;
    
    // Queue a command to load the id and title for each page.
    pages.load('id,title');
    
    // Run the queued commands, and return a promise to indicate task completion.
    await context.sync();
            
    // Display the properties.
    $.each(pages.items, function(index, page) {
        console.log(page.title);
        console.log(page.id);
    });
});

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): OneNote.PageCollection;

参数

propertyNamesAndPaths
OfficeExtension.LoadOption

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来,调用toJSON传递给它的 对象的 方法。) 虽然原始OneNote.PageCollection对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 OneNote.Interfaces.PageCollectionData) ,其中包含一个“items”数组,其中包含集合项中任何已加载属性的浅表副本。

toJSON(): OneNote.Interfaces.PageCollectionData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 的 context.trackedObjects.add(thisObject)简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在对对象设置属性或调用方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将对象添加到跟踪的对象集合。

track(): OneNote.PageCollection;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 的 context.trackedObjects.remove(thisObject)简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

untrack(): OneNote.PageCollection;

返回