javascript - 使用 syncfusion-react 文档编辑器查找第二次出现的文本。(Javascript)
问题描述
需要使用同步融合文档编辑器找到文本的第二次出现并以红色突出显示文本。
根据他们有 findAll() 方法的文档,它在整个文档中查找文本并以黄色突出显示。无论如何我可以自定义突出显示颜色并在文档中仅找到第二次出现?
replaceAll() {
let textToFind = document.getElementById('find_text').value;
let textToReplace = document.getElementById('replace_text').value;
if (textToFind !== '') {
// Find all the occurences of given text
this.documenteditor.searchModule.findAll(textToFind);
if (this.documenteditor.searchModule.searchResults.length > 0) {
// Replace all the occurences of given text
this.documenteditor.searchModule.searchResults.replaceAll(textToReplace);
}
}
}
render() {
return (<div>
<button onClick={this.replaceAll.bind(this)}>Replace All</button>
<DocumentEditorComponent id="container" ref={(scope) => { this.documenteditor = scope; }} isReadOnly={false} enableSelection={true} enableEditor={true} enableSearch={true}/>
</div>);
}
解决方案
关于自定义搜索结果
文档编辑器的最新版本 (17.4.49) 提供了自定义搜索突出显示颜色的选项。请参考以下示例代码
this.settings = { searchHighlightColor:'red' };
DocumentEditorContainerComponent id="container" ref={(scope) => { this.container = scope; }} style={{ 'display': 'block', 'height': '590px' }} documentEditorSettings={this.settings} enableToolbar={true} locale='en-US'/>
发行说明
https://ej2.syncfusion.com/react/documentation/release-notes/17.4.49/#document-editor
这有助于您自定义搜索结果的突出显示颜色
推荐阅读
- python - 尝试在 X 秒后编辑嵌入时出现 Discord.py 错误
- c# - 使用来自 system.data.sqlite.org 的二进制文件时无法加载 DLL 'SQLite.Interop.dll'
- java - 如何为 LiveData 查询 Room 数据库
在传递变量时 - postgresql - 无法使用 Docker 连接我的 postgres 数据库
- python - 如何为python程序跨平台设置内存限制?
- python - 在多线程 PyQt5 应用程序的异常中输入 pdb 时避免段错误?
- consistency - 哪些编译器为生成的 asm 代码提供保证(保证)?
- markdown - 在pandoc markdown的项目符号之间插入空行?
- java - 平方数的方法参数的困难
- api - 没有密码的xray rest api身份验证