Office用のJavaScript API、MS Word 2016、Visual Studio 2015を使用して開発しています。文書内に同じタイトルのRich Text ContentContolが複数あります。これらのContentControlをハンドラにバインドして、onBindingDataChanged通知を取得できるようにしようとしています。Wordの複数のContentControls(同じタイトルを持つ)にハンドラをバインドする方法はありますかOffice用Javascript APIの使用
独自のIDを持つ1つのハンドラにContentControlsをバインドする方法はありますか?または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);
}
複数contentcontrolsは、タイトル「CCTitle」と文書であるので、機能bindNamedItem
でaddFromNamedItemAsync
がエラーを与える:Multiple objects with the same name were found.
私がしようとしている何達成するためには、ContentControlsのIDとコンテンツのいずれかをユーザーが変更したときに取得する必要があります。何か助けてもらえますか?前もって感謝します。