PowerPoint.BindingCollection class
表示属于演示文稿的所有绑定对象的集合。
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Loads bindings.
await PowerPoint.run(async (context) => {
const bindings = context.presentation.bindings;
bindings.load("items");
await context.sync();
const bindingCount = bindings.items.length;
if (bindingCount === 0) {
console.log(`There are no bindings.`);
} else if (bindingCount === 1) {
console.log("There's 1 binding.");
} else {
console.log(`There are ${bindingCount} bindings.`);
}
bindings.items.forEach((binding) => {
getShapeForBindingId(binding.id).then((shape) => {
if (shape) {
console.log(`Binding ID: ${binding.id} refers to shape ID ${shape.id}`);
} else {
console.log(`Binding ID: ${binding.id} doesn't refers to shape.`);
}
});
});
populateBindingsDropdown(bindings.items);
});
方法
add(shape, binding |
向特定 Shape 添加新绑定。 如果绑定已使用提供的 ID,则会覆盖现有绑定。 |
add(shape, binding |
向特定 Shape 添加新绑定。 如果绑定已使用提供的 ID,则会覆盖现有绑定。 |
add |
基于当前选定内容添加新绑定。 如果所选内容有多个区域, |
add |
基于当前选定内容添加新绑定。 如果所选内容有多个区域, |
get |
获取集合中的绑定数量。 |
get |
按 ID 获取绑定对象。 如果没有与该 ID 绑定,则引发 ItemNotFoundException。 |
get |
根据其在项目数组中的位置获取绑定对象。 如果索引小于 0 或大于或等于集合中的项计数,则引发 InvalidArgumentException。 |
get |
按 ID 获取绑定对象。 如果绑定对象不存在,则此方法返回一个对象,其 |
load(options) | 将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
load(property |
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 |
toJSON() | 重写 JavaScript |
属性详细信息
context
items
方法详细信息
add(shape, bindingType, id)
向特定 Shape 添加新绑定。 如果绑定已使用提供的 ID,则会覆盖现有绑定。
add(shape: PowerPoint.Shape, bindingType: PowerPoint.BindingType, id: string): PowerPoint.Binding;
参数
- shape
- PowerPoint.Shape
要向其添加绑定的形状。
- bindingType
- PowerPoint.BindingType
绑定的类型。 请参阅 BindingType
。
- id
-
string
绑定的 ID。
返回
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
// Inserts an image with binding.
await PowerPoint.run(async (context) => {
const bindingId = (document.getElementById("temp-binding-id") as HTMLInputElement).value;
const slide = context.presentation.getSelectedSlides().getItemAt(0);
const myShape = slide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle, {
top: 100,
left: 30,
width: 200,
height: 200
});
myShape.fill.setImage(flowerImage);
context.presentation.bindings.add(myShape, PowerPoint.BindingType.shape, bindingId);
await context.sync();
const bindingsDropdown = document.getElementById("bindings-dropdown") as HTMLSelectElement;
const option = new Option(`Binding ${bindingId}`, bindingId);
// When a binding ID already exists, the binding is updated to refer to the new shape
// so select the existing item rather than add a new one.
const foundIndex = findDropdownItem(bindingsDropdown, option.text);
if (foundIndex < 0) {
bindingsDropdown.add(option);
bindingsDropdown.selectedIndex = bindingsDropdown.options.length - 1;
} else {
bindingsDropdown.selectedIndex = foundIndex;
}
});
add(shape, bindingTypeString, id)
向特定 Shape 添加新绑定。 如果绑定已使用提供的 ID,则会覆盖现有绑定。
add(shape: PowerPoint.Shape, bindingTypeString: "Shape", id: string): PowerPoint.Binding;
参数
- shape
- PowerPoint.Shape
要向其添加绑定的形状。
- bindingTypeString
-
"Shape"
绑定的类型。 请参阅 BindingType
。
- id
-
string
绑定的 ID。
返回
注解
addFromSelection(bindingType, id)
基于当前选定内容添加新绑定。 如果所选内容有多个区域, InvalidReference
则会返回错误。
addFromSelection(bindingType: PowerPoint.BindingType, id: string): PowerPoint.Binding;
参数
- bindingType
- PowerPoint.BindingType
绑定的类型。 请参阅 BindingType
。
- id
-
string
绑定的 ID。
返回
注解
addFromSelection(bindingTypeString, id)
基于当前选定内容添加新绑定。 如果所选内容有多个区域, InvalidReference
则会返回错误。
addFromSelection(bindingTypeString: "Shape", id: string): PowerPoint.Binding;
参数
- bindingTypeString
-
"Shape"
绑定的类型。 请参阅 BindingType
。
- id
-
string
绑定的 ID。
返回
注解
getCount()
获取集合中的绑定数量。
getCount(): OfficeExtension.ClientResult<number>;
返回
OfficeExtension.ClientResult<number>
注解
getItem(key)
按 ID 获取绑定对象。 如果没有与该 ID 绑定,则引发 ItemNotFoundException。
getItem(key: string): PowerPoint.Binding;
参数
- key
-
string
要检索的绑定对象的 ID。
返回
注解
示例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/binding-to-shapes.yaml
async function getShapeForBindingId(bindingId: string): Promise<PowerPoint.Shape | undefined> {
// Gets shape associated with binding ID.
return PowerPoint.run(async (context) => {
const binding = context.presentation.bindings.getItem(bindingId);
const shape = binding.getShape();
return shape;
});
}
getItemAt(index)
根据其在项目数组中的位置获取绑定对象。 如果索引小于 0 或大于或等于集合中的项计数,则引发 InvalidArgumentException。
getItemAt(index: number): PowerPoint.Binding;
参数
- index
-
number
要检索的对象的索引值。 从零开始编制索引。
返回
注解
getItemOrNullObject(id)
按 ID 获取绑定对象。 如果绑定对象不存在,则此方法返回一个对象,其 isNullObject
属性设置为 true
。 有关详细信息,请参阅 *OrNullObject 方法和属性。
getItemOrNullObject(id: string): PowerPoint.Binding;
参数
- id
-
string
要检索的绑定对象的 ID。
返回
注解
load(options)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(options?: PowerPoint.Interfaces.BindingCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions): PowerPoint.BindingCollection;
参数
- options
-
PowerPoint.Interfaces.BindingCollectionLoadOptions & PowerPoint.Interfaces.CollectionLoadOptions
提供要加载对象的属性的选项。
返回
load(propertyNames)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNames?: string | string[]): PowerPoint.BindingCollection;
参数
- propertyNames
-
string | string[]
逗号分隔的字符串或指定要加载的属性的字符串数组。
返回
load(propertyNamesAndPaths)
将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()
。
load(propertyNamesAndPaths?: OfficeExtension.LoadOption): PowerPoint.BindingCollection;
参数
- propertyNamesAndPaths
- OfficeExtension.LoadOption
propertyNamesAndPaths.select
是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand
一个逗号分隔的字符串,指定要加载的导航属性。
返回
toJSON()
重写 JavaScript toJSON()
方法,以便在将 API 对象传递给 JSON.stringify()
时提供更有用的输出。
JSON.stringify
(,反过来,调用toJSON
传递给它的 对象的 方法。) 而原始PowerPoint.BindingCollection
对象是 API 对象,toJSON
该方法返回一个纯 JavaScript 对象, (类型为 PowerPoint.Interfaces.BindingCollectionData
) ,其中包含一个“items”数组,其中包含集合项中任何已加载属性的浅表副本。
toJSON(): PowerPoint.Interfaces.BindingCollectionData;