I'm developing with JavaScript API for Office, MS Word 2016, VisualStudio 2015. There are multiple Rich Text ContentContols with a same title in the document. I'm trying to bind these ContentControls to a handler so that I can get onBindingDataChanged notification.
Is there a way to bind the ContentControls to one handler with their own ID? or pass ContentControls' id as one parameter?
My current code is like:
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);
}
Since there are multiple contentcontrols in the document with title "CCTitle", addFromNamedItemAsync
in function bindNamedItem
will give error: Multiple objects with the same name were found.
What I'm trying to achieve is to get the ContentControls' id and content whenever the user make some change to any of them. Is there any idea to help? Thanks in advance.