Javascript: DocumentTargetCollection.getItem Method
Description
Gets the document target at the current text input position or the document target with the specified id.
Syntax
<void> DocumentTargetCollection.getItem(<RequestDocumentTargetCallback> callback, [<ErrorCallback> errorCallback], [<number> nameOrId])Parameters
| Parameter | Description |
|---|---|
| callback | The callback function that receives the requested value. |
| errorCallback | Optional. Is called when the operation failed with an error. |
| nameOrId | Optional. Specifies either the document target's identifier set with the ID property or the document target's target name set with the TargetName property. The method returns null if a target with the specified identifier or name does not exist. |
Examples
The following example demonstrates DocumentTargetCollection.getItem in a practical document-editing workflow. It gets the document target at the current text input position or the document target with the specified id.
function onTxError(error) {
console.error("TX Text Control error:", error.msg);
error.handled = true;
}
TXTextControl.textParts.getMainText(function(mainText) {
const documentTargets = mainText.documentTargets;
documentTargets.getItem(
function(result) {
if (!result) {
console.warn("No document target was returned.");
return;
}
console.log("get item result:", result);
},
onTxError,
25
);
}, onTxError);