2016-11-22 119 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进行了更新,现在我们有方法的味道:) –

相关问题