Office、MS Word 2016、VisualStudio 2015 用の JavaScript API を使用して開発しています。ドキュメント内に同じタイトルのリッチ テキスト ContentContols が複数あります。onBindingDataChanged 通知を取得できるように、これらの ContentControls をハンドラーにバインドしようとしています。
ContentControls を独自の ID を持つ 1 つのハンドラーにバインドする方法はありますか? または ContentControls の ID を 1 つのパラメーターとして渡しますか?
私の現在のコードは次のようなものです:
function bindNamedItem() {
Office.context.document.bindings.addFromNamedItemAsync("CCTitle", Office.BindingType.Text, { id: 'ccbind' }, function (result) {
if (result.status == 'succeeded') {
console.log('Added new binding with type: ' + result.value.type + ' and id: ' + result.value.id);
}
else
console.log('Error: ' + result.error.message);
});
}
function addEventHandlerToBinding() {
Office.select("bindings#ccbind").addHandlerAsync(Office.EventType.BindingDataChanged, onBindingDataChanged);
}
var onBindingDataChanged = function (result) {
console.log(result);
}
タイトルが「CCTitle」のドキュメントには複数のコンテンツ コントロールがあるためaddFromNamedItemAsync
、関数内でbindNamedItem
エラーが発生します。Multiple objects with the same name were found.
私が達成しようとしているのは、ユーザーがそれらのいずれかに何らかの変更を加えるたびに、ContentControls の ID とコンテンツを取得することです。役立つアイデアはありますか?前もって感謝します。