使用matchWildcards的Office-js Range.search失败

时间:2018-12-14 03:30:02

标签: office-js

我正在使用Office-js开发Word Addin女士。下面的代码在Word桌面上工作正常,但在Word Online上,浏览器在处理代码时停止响应。我有以下代码:

Word.run(function (context) {
     let body = document.body;
     body.load('text');
     return context.sync().then(function () {
        var searchTerms = findAllSearchTerms(body.text);
        var results = [];
        for (let i = 0; i < searchTerms.length; i++) {
            results[i] = context.document.body.search(searchTerms[i]);
        };
        for (let i =0; i<results.length; i++){
            results[i].load('font/italic, font/underline, text');
        };
        return context.sync().then(function () {
            var results2 = [];
            for (let b=0; b<results.length;b++){
                results[b].items.forEach(function(r){
                    results2.push(r);
                })
            }
            var newResults= [];
            var newResultsShort = [];
             for (let i = 0; i < results2.length; i++) {
                if(results2[i].text.toLowerCase().includes('supra')){
                    //This is where the browser stops responding. If I remove matchWildcards option, it runs fine but the desired results are not achieved.
                    newResultsShort.push(results2[i].search("<*>", { matchWildcards: true }));
                } else {
                    newResults.push(results2[i]);
                }
            };
        )}
     })
})
.catch(function (error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    };
});

在这里,我正在搜索整个文档。然后,我搜索结果中的特定模式。在结果范围内执行搜索时,我无法使用matchWildcards选项。

0 个答案:

没有答案
相关问题