mathjax - 即使 readOnly 为 True,草稿 js mathjax 插件也始终可编辑
问题描述
这是我的代码
class DraftQuestion extends React.Component {
constructor(props) {
super(props);
this.state = {readOnly: true};
const content = window.localStorage.getItem('content');
if (content) {
this.state.editorState = EditorState.createWithContent(convertFromRaw(JSON.parse(content)));
} else {
this.state.editorState = EditorState.createEmpty();
}
this.handleKeyCommand = this.handleKeyCommand.bind(this);
this.mathjaxPlugin = createMathjaxPlugin();
}
saveContent = (content) => {
window.localStorage.setItem('content', JSON.stringify(convertToRaw(content)));
}
onChange = (editorState) => {
let content = this.state.editorState.getCurrentContent()
this.saveContent(content);
this.setState({ editorState })
}
render() {
this.plugins = [
this.mathjaxPlugin,
]
return (
<div>
<Editor
editorState={this.state.editorState}
handleKeyCommand={this.handleKeyCommand}
readOnly={true}
onChange={this.onChange}
plugins={this.plugins}
readOnly={this.state.readOnly}
/>
</div>
);
}
}
在这里你可以看到 readOnly 是true
,但是当我执行代码并显示文本时,文本是不可编辑的(正如预期的那样,因为 readOnly 字段)但是添加的数学方程(例如 \alpha 或 \sigma)mathjaxPlugin
仍然是可编辑。
解决方案
推荐阅读
- azure - 如何在 Databricks 上的 SparkListener 中使用 dbutils
- python - 从 Morningstart 检索股票数据
- android - 撰写具有透明背景的圆形按钮
- javascript - 如何在 Web 应用程序中创建带有可选输入字段的 fetch url
- ubuntu - Google Cloud VM 中的后台进程在一段时间后终止
- android - 在 Android Studio 中按住时如何更改按钮的背景颜色?
- selenium - 从 Selenium 3.11.0 升级到 4.0.0 找不到 Chrome 选项 setExperimentalOption 方法
- python - 当我尝试使用 Python 3.8 在 jupyter notebook 中安装 PySimpleGUI (4.53.0) 时,错误“没有返回名为‘PySimpleGUI’的模块
- html - 如何使用 CSS 设置背景图像?
- javascript - 添加时间戳 discord.js 存在