我已經爲運行搜索的單詞創建了一個任務窗格插件,並將爲搜索結果的第一段顯示文本。 直到前兩天下面的代碼成功運行: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進行了更新,現在我們有方法的味道:) –