我已经为运行搜索的单词创建了一个任务窗格插件,并将为搜索结果的第一段显示文本。 直到前两天下面的代码成功运行:paragraphCollection.first应该如何用于javascript api
function onGetFirstRangeParaClick() {
var textToFind = "Word",
range,
paragraph;
return Word.run(function (context) {
var searchResults = context.document.body.search(textToFind, { matchWildCards: false });
context.load(searchResults, "text");
return context.sync()
.then(function() {
range = searchResults.items[0].getRange();
context.load(range, "text, paragraphs");
return context.sync();
})
.then(function() {
paragraph = range.paragraphs.first;
context.load(paragraph, "text");
return context.sync();
})
.then(function() {
$("#getFirstRangeParaResult").text(paragraph.text);
});
})
.catch(onError);
}
但是现在被抛出以下错误:
{"name":"OfficeExtension.Error","code":"GeneralException","message":"GeneralException","traceMessages":[],"debugInfo":{"errorLocation":"ParagraphCollection.first"},"stack":"GeneralException: GeneralException\\n at Anonymous function (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:8360:6)\\n at lib$es6$promise$$internal$$tryCatch (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9595:8)\\n at lib$es6$promise$$internal$$invokeCallback (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9605:8)\\n at lib$es6$promise$$internal$$publish (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9581:9)\\n at lib$es6$promise$asap$$flush (https://appsforoffice.microsoft.com/lib/beta/hosted/word-win32-16.01.debug.js:9400:8)"}
我使用的调试PreviewCDN(//appsforoffice.microsoft。 COM/lib目录/测试/托管/ office.debug.js) 和正在运行的Office版本1610(生成7466.2038)
我在API文档注意到paragraphs.first
正在改变paragraphs.getFirst()
但不像这又是实现为如果我改变使用getFirst()
我得到以下错误:
Object doesn't support property or method 'getFirst'
我应该如何使用第一或getFirst()的ParagraphCollection?
跟进这个BETA CDN进行了更新,现在我们有方法的味道:) –