我正在使用 word javascript api 开发一个 word 插件,并且需要获取 contentControl 以进行当前选择,因此使用 parentContentControl 进行当前选择。
**Code:**
var range = context.document.getSelection().parentContentControl;
context.load(range);
但在控制台上显示错误:错误:{"name":"OfficeExtension.Error","code":"GeneralException","message":"GeneralException","traceMessages":[],"debugInfo":{"errorLocation":"Range.parentContentControl"},"stack":"GeneralException: GeneralException\n at Anonymous function (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.01.js:19:189006)\n at pi (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.01.js:19:211583)\n at ht (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.01.js:19:211670)\n at g (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.01.js:19:211490)\n at l (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.01.js:19:210076)"}
Debug info: {"errorLocation":"Range.parentContentControl"}
如果当前选择不包含任何 contentControl 它应该返回 NULL,但它会给出错误。请指教。
谢谢。