Office.Categories interface

表示项的类别。

在 Outlook 中,用户可以通过使用类别对邮件和约会进行颜色编码来标记邮件和约会。 用户在其邮箱 的主列表中定义类别 。 然后,他们可以将一个或多个类别应用于项目。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件的类别。

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

方法

addAsync(categories, options, callback)

向项添加类别。 每个类别必须位于该邮箱的类别主列表中,因此必须具有唯一的名称,但多个类别可以使用相同的颜色。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件或约会项目的类别。

addAsync(categories, callback)

向项添加类别。 每个类别必须位于该邮箱的类别主列表中,因此必须具有唯一的名称,但多个类别可以使用相同的颜色。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件或约会项目的类别。

getAsync(options, callback)

获取项的类别。

重要说明

  • 如果项目上没有类别, null 或者将根据 Outlook 版本返回空数组,因此请确保同时处理这两种情况。

  • 在Outlook 网页版中,不能使用 API 来管理在撰写模式下应用于消息的类别。

getAsync(callback)

获取项的类别。

重要说明

  • 如果项目上没有类别, null 或者将根据 Outlook 版本返回空数组,因此请确保同时处理这两种情况。

  • 在Outlook 网页版中,不能使用 API 来管理在撰写模式下应用于消息的类别。

removeAsync(categories, options, callback)

从项中删除类别。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件的类别。

removeAsync(categories, callback)

从项中删除类别。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件的类别。

方法详细信息

addAsync(categories, options, callback)

向项添加类别。 每个类别必须位于该邮箱的类别主列表中,因此必须具有唯一的名称,但多个类别可以使用相同的颜色。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件或约会项目的类别。

addAsync(categories: string[], options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

categories

string[]

要添加到项的类别。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:撰写或阅读

错误

  • InvalidCategory:提供的类别无效。

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-categories.yaml

// Note: In order for you to successfully add a category,
// it must be in the mailbox categories master list.

Office.context.mailbox.masterCategories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const masterCategories = asyncResult.value;
    if (masterCategories && masterCategories.length > 0) {
      // Grab the first category from the master list.
      const categoryToAdd = [masterCategories[0].displayName];
      Office.context.mailbox.item.categories.addAsync(categoryToAdd, function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
          console.log(`Successfully assigned category '${categoryToAdd}' to item.`);
        } else {
          console.log("categories.addAsync call failed with error: " + asyncResult.error.message);
        }
      });
    } else {
      console.log("There are no categories in the master list on this mailbox. You can add categories using Office.context.mailbox.masterCategories.addAsync.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

addAsync(categories, callback)

向项添加类别。 每个类别必须位于该邮箱的类别主列表中,因此必须具有唯一的名称,但多个类别可以使用相同的颜色。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件或约会项目的类别。

addAsync(categories: string[], callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

categories

string[]

要添加到项的类别。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:撰写或阅读

错误

  • InvalidCategory:提供的类别无效。

getAsync(options, callback)

获取项的类别。

重要说明

  • 如果项目上没有类别, null 或者将根据 Outlook 版本返回空数组,因此请确保同时处理这两种情况。

  • 在Outlook 网页版中,不能使用 API 来管理在撰写模式下应用于消息的类别。

getAsync(options: Office.AsyncContextOptions, callback: (asyncResult: Office.AsyncResult<CategoryDetails[]>) => void): void;

参数

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。

callback

(asyncResult: Office.AsyncResult<Office.CategoryDetails[]>) => void

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果获取类别失败,属性 asyncResult.error 将包含错误代码。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

getAsync(callback)

获取项的类别。

重要说明

  • 如果项目上没有类别, null 或者将根据 Outlook 版本返回空数组,因此请确保同时处理这两种情况。

  • 在Outlook 网页版中,不能使用 API 来管理在撰写模式下应用于消息的类别。

getAsync(callback: (asyncResult: Office.AsyncResult<CategoryDetails[]>) => void): void;

参数

callback

(asyncResult: Office.AsyncResult<Office.CategoryDetails[]>) => void

方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果获取类别失败,属性 asyncResult.error 将包含错误代码。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读取项

适用的 Outlook 模式:撰写或阅读

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-categories.yaml

Office.context.mailbox.item.categories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const categories = asyncResult.value;
    if (categories && categories.length > 0) {
      console.log("Categories assigned to this item:");
      console.log(JSON.stringify(categories));
    } else {
      console.log("There are no categories assigned to this item.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

removeAsync(categories, options, callback)

从项中删除类别。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件的类别。

removeAsync(categories: string[], options: Office.AsyncContextOptions, callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

categories

string[]

要从项中删除的类别。

options
Office.AsyncContextOptions

包含以下一个或多个属性的对象文本:- asyncContext:开发人员可以在回调函数中提供他们想要访问的任何对象。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果删除类别失败,属性 asyncResult.error 将包含错误代码。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:撰写或阅读

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-categories.yaml

Office.context.mailbox.item.categories.getAsync(function(asyncResult) {
  if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
    const categories = asyncResult.value;
    if (categories && categories.length > 0) {
      // Grab the first category assigned to this item.
      const categoryToRemove = [categories[0].displayName];
      Office.context.mailbox.item.categories.removeAsync(categoryToRemove, function(asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
          console.log(`Successfully unassigned category '${categoryToRemove}' from this item.`);
        } else {
          console.log("categories.removeAsync call failed with error: " + asyncResult.error.message);
        }
      });
    } else {
      console.log("There are no categories assigned to this item.");
    }
  } else {
    console.error(asyncResult.error);
  }
});

removeAsync(categories, callback)

从项中删除类别。

重要提示:在 Outlook 网页版 中,不能使用 API 来管理在撰写模式下应用于邮件的类别。

removeAsync(categories: string[], callback?: (asyncResult: Office.AsyncResult<void>) => void): void;

参数

categories

string[]

要从项中删除的类别。

callback

(asyncResult: Office.AsyncResult<void>) => void

可选。 方法完成后,使用类型的Office.AsyncResult单个参数调用在 参数中callback传递的函数。 如果删除类别失败,属性 asyncResult.error 将包含错误代码。

返回

void

注解

[ API set: Mailbox 1.8 ]

最低权限级别读/写项

适用的 Outlook 模式:撰写或阅读