Word.ComboBoxContentControl class    
特定于 类型 comboBox的内容控件的数据。
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-combo-box-content-control.yaml
// Places a combo box content control at the end of the selection.
await Word.run(async (context) => {
  let selection = context.document.getSelection();
  selection.getRange(Word.RangeLocation.end).insertContentControl(Word.ContentControlType.comboBox);
  await context.sync();
  console.log("Combo box content control inserted at the end of the selection.");
});
方法
| add | 向此组合框内容控件添加新的列表项并返回Word。ContentControlListItem 对象。 | 
| delete | 删除此组合框内容控件中的所有列表项。 | 
| load(property | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用  | 
| load(property | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用  | 
| toJSON() | 重写 JavaScript  | 
| track() | 根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨  | 
| untrack() | 释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用  | 
属性详细信息
context
		listItems
	 
	获取组合框内容控件中列表项的集合。
readonly listItems: Word.ContentControlListItemCollection;属性值
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-combo-box-content-control.yaml
// Deletes the provided list item from the first combo box content control in the selection.
await Word.run(async (context) => {
  const listItemText = (document.getElementById("item-to-delete") as HTMLInputElement).value.trim();
  const selectedRange: Word.Range = context.document.getSelection();
  let selectedContentControl = selectedRange
    .getContentControls({
      types: [Word.ContentControlType.comboBox]
    })
    .getFirstOrNullObject();
  selectedContentControl.load("id,comboBoxContentControl");
  await context.sync();
  if (selectedContentControl.isNullObject) {
    const parentContentControl: Word.ContentControl = selectedRange.parentContentControl;
    parentContentControl.load("id,type,comboBoxContentControl");
    await context.sync();
    if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.comboBox) {
      console.warn("No combo box content control is currently selected.");
      return;
    } else {
      selectedContentControl = parentContentControl;
    }
  }
  let selectedComboBox: Word.ComboBoxContentControl = selectedContentControl.comboBoxContentControl;
  selectedComboBox.listItems.load("items/*");
  await context.sync();
  let listItems: Word.ContentControlListItemCollection = selectedContentControl.comboBoxContentControl.listItems;
  let itemToDelete: Word.ContentControlListItem = listItems.items.find((item) => item.displayText === listItemText);
  if (!itemToDelete) {
    console.warn(`List item doesn't exist in control with ID ${selectedContentControl.id}: ${listItemText}`);
    return;
  }
  itemToDelete.delete();
  await context.sync();
  console.log(`List item deleted from control with ID ${selectedContentControl.id}: ${listItemText}`);
});
方法详细信息
		addListItem(displayText, value, index)
	   
	向此组合框内容控件添加新的列表项并返回Word。ContentControlListItem 对象。
addListItem(displayText: string, value?: string, index?: number): Word.ContentControlListItem;参数
- displayText
- 
				string 
显示列表项的文本。
- value
- 
				string 
可选。 列表项的值。
- index
- 
				number 
可选。 列表中新项的索引位置。 如果在指定的位置已有某项,则该现有项将在列表中下移。 如果省略它,则新项将添加到列表的末尾。
返回
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-combo-box-content-control.yaml
// Adds the provided list item to the first combo box content control in the selection.
await Word.run(async (context) => {
  const listItemText = (document.getElementById("item-to-add") as HTMLInputElement).value.trim();
  const selectedRange: Word.Range = context.document.getSelection();
  let selectedContentControl = selectedRange
    .getContentControls({
      types: [Word.ContentControlType.comboBox]
    })
    .getFirstOrNullObject();
  selectedContentControl.load("id,comboBoxContentControl");
  await context.sync();
  if (selectedContentControl.isNullObject) {
    const parentContentControl: Word.ContentControl = selectedRange.parentContentControl;
    parentContentControl.load("id,type,comboBoxContentControl");
    await context.sync();
    if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.comboBox) {
      console.warn("No combo box content control is currently selected.");
      return;
    } else {
      selectedContentControl = parentContentControl;
    }
  }
  selectedContentControl.comboBoxContentControl.addListItem(listItemText);
  await context.sync();
  console.log(`List item added to control with ID ${selectedContentControl.id}: ${listItemText}`);
});
		deleteAllListItems()
	   
	删除此组合框内容控件中的所有列表项。
deleteAllListItems(): void;返回
void
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/10-content-controls/insert-and-change-combo-box-content-control.yaml
// Deletes the list items from first combo box content control found in the selection.
await Word.run(async (context) => {
  const selectedRange: Word.Range = context.document.getSelection();
  let selectedContentControl = selectedRange
    .getContentControls({
      types: [Word.ContentControlType.comboBox]
    })
    .getFirstOrNullObject();
  selectedContentControl.load("id,comboBoxContentControl");
  await context.sync();
  if (selectedContentControl.isNullObject) {
    const parentContentControl: Word.ContentControl = selectedRange.parentContentControl;
    parentContentControl.load("id,type,comboBoxContentControl");
    await context.sync();
    if (parentContentControl.isNullObject || parentContentControl.type !== Word.ContentControlType.comboBox) {
      console.warn("No combo box content control is currently selected.");
      return;
    } else {
      selectedContentControl = parentContentControl;
    }
  }
  console.log(`About to delete the list from the combo box content control with ID ${selectedContentControl.id}`);
  selectedContentControl.comboBoxContentControl.deleteAllListItems();
  await context.sync();
  console.log("Deleted the list from the combo box content control.");
});
		load(propertyNames)
	 
	将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNames?: string | string[]): Word.ComboBoxContentControl;参数
- propertyNames
- 
				string | string[] 
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
		load(propertyNamesAndPaths)
	   
	将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()。
load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Word.ComboBoxContentControl;参数
- propertyNamesAndPaths
- 
				{ select?: string; expand?: string; } 
              propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。
返回
toJSON()
重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 
              JSON.stringify
               (,依次调用toJSON传递给它的 对象的 方法。) 虽然原始Word.ComboBoxContentControl对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Word.Interfaces.ComboBoxContentControlData) ,其中包含从原始对象加载的任何子属性的浅表副本。
toJSON(): Word.Interfaces.ComboBoxContentControlData;返回
track()
根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 .sync 调用和“.run”批处理的顺序执行外部使用此对象,并在设置属性或调用对象方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将该对象添加到跟踪的对象集合。 如果此对象是集合的一部分,则还应跟踪父集合。
track(): Word.ComboBoxContentControl;返回
untrack()
释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存发布生效之前,需要调用 context.sync() 。
untrack(): Word.ComboBoxContentControl;