【发布时间】:2019-04-06 17:14:00
【问题描述】:
基本上,我必须突出显示我在数组中收到的单词。在控制台上,我在第一次迭代后收到以下错误:
未处理的拒绝 PropertyNotLoaded:属性“项目”不可用。在读取属性值之前,调用包含对象的 load 方法,并在关联的请求上下文中调用“context.sync()”。
代码如下:
var color = systemService.getColor(item.gradeText);
var filteredWords = $(item.words).not($scope.stopList).get();
Word.run(function (context) {
var selectedRange = context.document.getSelection();
context.load(selectedRange, "text");
return context.sync().then(function () {
for (var i = 0; i < filteredWords.length; i++) {
var searchResults = null;
searchResults = selectedRange.search(filteredWords[i], { ignorePunct: true, matchCase: false, matchWholeWord: true });
context.load(searchResults, 'font');
context.sync().then(function () {
for (var i = 0; i < searchResults.items.length; i++) {
searchResults.items[i].font.color = color;
searchResults.items[i].font.bold = true;
}
});
}
}).then(context.sync);
})
.catch(function (error) {
console.log('Error: ' + JSON.stringify(error));
if (error instanceof OfficeExtension.Error) {
console.log('Debug info: ' + JSON.stringify(error.debugInfo));
}
});
【问题讨论】:
标签: ms-office office-js office-addins word-addins