2016-11-22 16 views
0

我已經爲運行搜索的單詞創建了一個任務窗格插件,並將爲搜索結果的第一段顯示文本。 直到前兩天下面的代碼成功運行: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?

回答

0

感謝您使用預覽。實際上,正如你所提到的,我們對一些屬性做了一些修改(即obj.first,obj.last,obj.previous,obj.next分別改名爲getFirst(),getLast(),getLast()和getPrevious()所有支持這些功能的對象

如果您安裝最新的內部緩慢構建(16.0.7571.2006)或者如果您在內部快速構建,那麼您應該看到這些更改正常工作預覽Office.js將同步與構建16.7571+

感謝,並希望這闡明這是怎麼回事..

+0

跟進這個BETA CDN進行了更新,現在我們有方法的味道:) –

相關問題