簡體   English   中英

javascript API一詞應如何使用paragraphCollection.first

[英]How should paragraphCollection.first be used in the word 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/beta/hosted/office.debug.js),並且正在運行Office版本1610(內部版本7466.2038)

我在Api文檔中注意到, paragraphs.first .first正在更改為paragraphs.getFirst() .getFirst paragraphs.getFirst()但它似乎尚未實現,就好像我更改為使用getFirst() ,出現以下錯誤:

Object doesn't support property or method 'getFirst'  

我應該如何對ParagraphCollection使用first或getFirst()?

感謝您使用預覽。 就像您提到的那樣,實際上,我們對某些屬性進行了一些更改(即obj.first,obj.last,obj.previous,obj.next分別重命名為getFirst(),getLast(),getLast()和getPrevious())。支持這些功能的所有對象。

如果您安裝了最新的內部人員內部版本(16.0.7571.2006),或者您正在內部人員內部快速版本中,則應該看到所做的更改。 預覽版Office.js將與內部版本16.7571+同步

謝謝,希望這可以澄清正在發生的事情。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM