如何在Draft.js中使用策略函数Decorator?

How to use strategy function Decorator in Draft.js?

我一直在玩 Draft.js 中的装饰器,但是当我无法构建自定义装饰器时 我将文本发送到 API,我将收到一个包含在编辑器中键入的错误单词数组的响应,因此我正在尝试构建一个策略函数,将样式应用于该数组中的所有项目

 function highlightWorngWords(contentBlock, callback) {
    let text = contentBlock.getText();
    let worngWords = ['word', 'word1' , 'word2'];
    while ( worngWords  !== null ) {
      start = worngWords.index;
      callback(start, start + worngWords[0].length);
    }  
  }

我错过了什么它不起作用?

function highlightWorngWords(contentBlock, callback) {
    let text = contentBlock.getText();
    let worngWords = ['word', 'word1' , 'word2'];
    worngWords.forEach(word => {
      start = text.indexOf(word);
      if (start !== -1) {
         callback(start, start + word.length);
      }
    })
  }

你想做这样的事情吗?