Word.ConflictCollection class

表示 Word 文档中的共同创作冲突。

扩展

注解

API 集:WordApiDesktop 1.4

使用方

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-conflicts.yaml

// Gets all coauthoring conflicts in the document.
await Word.run(async (context) => {
  const conflicts: Word.ConflictCollection = context.document.coauthoring.conflicts;
  conflicts.load("items/type");
  await context.sync();

  if (conflicts.items.length === 0) {
    console.log("No conflicts found in the document.");
    return;
  }

  console.log(`Found ${conflicts.items.length} conflict(s):`);
  for (let i = 0; i < conflicts.items.length; i++) {
    console.log(`  Conflict ${i + 1}: type = ${conflicts.items[i].type}`);
  }
});

属性

context

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

items

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

方法

acceptAll()

接受所有用户的更改、 删除冲突,并将所做的更改合并到文档的服务器副本。

getItem(index)

按对象在集合中的索引获取 Conflict 对象。

load(options)

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

load(propertyNames)

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

load(propertyNamesAndPaths)

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

rejectAll()

拒绝所有用户的更改,并保留文档的服务器副本。

toJSON()

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

track()

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

untrack()

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

属性详细信息

context

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

context: RequestContext;

属性值

items

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

readonly items: Word.Conflict[];

属性值

方法详细信息

acceptAll()

接受所有用户的更改、 删除冲突,并将所做的更改合并到文档的服务器副本。

acceptAll(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-conflicts.yaml

// Accepts all user changes, removes all conflicts, and merges into the server copy.
await Word.run(async (context) => {
  context.document.coauthoring.conflicts.acceptAll();
  await context.sync();

  console.log("All conflicts accepted (all your changes kept).");
});

getItem(index)

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

按对象在集合中的索引获取 Conflict 对象。

getItem(index: number): Word.Conflict;

参数

index

number

对象的位置 Conflict

返回

注解

API 集:WordApi BETA (仅预览版)

load(options)

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

load(options?: Word.Interfaces.ConflictCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions): Word.ConflictCollection;

参数

options

Word.Interfaces.ConflictCollectionLoadOptions & Word.Interfaces.CollectionLoadOptions

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

返回

load(propertyNames)

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

load(propertyNames?: string | string[]): Word.ConflictCollection;

参数

propertyNames

string | string[]

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

返回

load(propertyNamesAndPaths)

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

load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Word.ConflictCollection;

参数

propertyNamesAndPaths
OfficeExtension.LoadOption

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

返回

rejectAll()

拒绝所有用户的更改,并保留文档的服务器副本。

rejectAll(): void;

返回

void

注解

API 集:WordApiDesktop 1.4

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/05-coauthoring/manage-coauthoring-conflicts.yaml

// Rejects all user changes and retains the server copy for all conflicts.
await Word.run(async (context) => {
  context.document.coauthoring.conflicts.rejectAll();
  await context.sync();

  console.log("All conflicts rejected (server copy kept for all).");
});

toJSON()

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

toJSON(): Word.Interfaces.ConflictCollectionData;

返回

track()

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

track(): Word.ConflictCollection;

返回

untrack()

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

untrack(): Word.ConflictCollection;

返回