OfficeExtension.LoadOption interface

指定应加载对象的哪些属性。Specifies which properties of an object should be loaded. 当执行 sync () 方法时, 将发生此负载。This load happens when the sync() method is executed. 这将同步 Office 对象与对应的 JavaScript 代理对象之间的状态。This synchronizes the states between Office objects and corresponding JavaScript proxy objects.

注解

对于 Word, 指定属性和分页信息的首选方法是使用字符串文字。For Word, the preferred method for specifying the properties and paging information is by using a string literal. 前两个示例说明了请求段落集合中段落的文本和字体大小属性的首选方法:The first two examples show the preferred way to request the text and font size properties for paragraphs in a paragraph collection:

context.load(paragraphs, 'text, font/size');

paragraphs.load('text, font/size');

下面是使用对象表示法(包括分页)的类似示例:Here is a similar example using object notation (includes paging):

context.load(paragraphs, {select: 'text, font/size', expand: 'font', top: 50, skip: 0});

paragraphs.load({select: 'text, font/size', expand: 'font', top: 50, skip: 0});

请注意,如果我们未在 select 语句中指定字体对象的特定属性,expand 语句本身将指示需加载所有字体属性。Note that if we don't specify the specific properties on the font object in the select statement, the expand statement by itself would indicate that all of the font properties are loaded.

示例Examples

// This example shows how to get the paragraphs in the Word document
// along with their text and font size properties.

// Run a batch operation against the Word object model.
Word.run(function (context) {
    // Create a proxy object for the paragraphs collection.
    var paragraphs = context.document.body.paragraphs;

    // Queue a commmand to load the text and font properties.
    // It is best practice to always specify the property set.
    // Otherwise, all properties are returned on the object.
    context.load(paragraphs, 'text, font/size');

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        // Insert code that works with the paragraphs loaded by context.load().
    })
})
.catch(function (error) {
    console.log('Error: ' + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log('Debug info: ' + JSON.stringify(error.debugInfo));
    }
});

属性

expand

以逗号分隔的字符串或字符串数组, 用于指定要加载的导航属性。A comma-delimited string, or array of strings, that specifies the navigation properties to load.

select

以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string, or array of strings, that specifies the properties to load.

skip

仅对集合类型可用。Only usable on collection types. 指定要跳过且不包含在结果中的集合中的项目数。Specifies the number of items in the collection that are to be skipped and not included in the result. 如果指定 top, 则在跳过指定数目的项目后, 将启动结果集。If top is specified, the result set will start after skipping the specified number of items.

top

仅对集合类型可用。Only usable on collection types. 指定结果中可以包含的集合项最大数量。Specifies the maximum number of collection items that can be included in the result.

属性详细信息

expand

以逗号分隔的字符串或字符串数组, 用于指定要加载的导航属性。A comma-delimited string, or array of strings, that specifies the navigation properties to load.

expand?: string | string[];

属性值

string | string[]

select

以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string, or array of strings, that specifies the properties to load.

select?: string | string[];

属性值

string | string[]

skip

仅对集合类型可用。Only usable on collection types. 指定要跳过且不包含在结果中的集合中的项目数。Specifies the number of items in the collection that are to be skipped and not included in the result. 如果指定 top, 则在跳过指定数目的项目后, 将启动结果集。If top is specified, the result set will start after skipping the specified number of items.

skip?: number;

属性值

number

top

仅对集合类型可用。Only usable on collection types. 指定结果中可以包含的集合项最大数量。Specifies the maximum number of collection items that can be included in the result.

top?: number;

属性值

number

示例Examples

// This OneNote example shows how to get the page title and indentation level
// of the top five pages in the current section.
OneNote.run(function (context) {
    // Get the pages in the current section.
    var pages = context.application.getActiveSection().pages;

    // Queue a command to load the pages.           
    pages.load({ "select":"title,pageLevel", "top":5, "skip":0 });
    return context.sync()
        .then(function() {
            // Iterate through the collection of pages.    
            $.each(pages.items, function(index, page) {
                // Show some properties.
                console.log("Page title: " + page.title);
                console.log("Indentation level: " + page.pageLevel);
            });
        }).catch(function(error) {
            console.log("Error: " + error);
            if (error instanceof OfficeExtension.Error) {
                console.log("Debug info: " + JSON.stringify(error.debugInfo));
            }
        })
    });