如何在 React js 中从 tinymce 编辑器中获取值?
How to get value from tinymc editor in react js?
我正在尝试使用 React js 从 tinyms
编辑器渲染它在控制台中显示未定义的数据。我想使用 React js 向 tinyms
编辑器写入一些内容。请帮我解决这个问题..
import React, { Component } from 'react';
import { Editor } from '@tinymce/tinymce-react';
class AddEvent extends Component {
constructor() {
super();
this.state = {
content: '',
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this.content);
}
render() {
return (
<form>
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{ plugins: 'link image code',
toolbar: 'undo redo | bold italic| alignleft aligncenter alignright | code'
}}
onChange={this.handleEditorChange}
/>
<div className="col-md-3">
<button className="btn btn-block btn-primary btn-lg" type="submit">Save Event</button>
</div>
</form>
函数绑定类似于 .bind(this)
,但您绑定 handleEditorChange
的值不正确
改变
this.handleEditorChange = this.handleEditorChange.bind(this.content);
至
this.handleEditorChange = this.handleEditorChange.bind(this);
请在下面找到更正后的代码以及其他更改。这将按预期工作
import React, { Component } from 'react';
import { Editor } from '@tinymce/tinymce-react';
class AddEvent extends Component {
constructor() {
super();
this.state = {
content: '',
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this);
}
handleEditorChange(e){
console.log('Content was updated:', e.target.getContent());
this.setState({content: e.target.getContent()});
}
render() {
const content = <p>This is the initial content of the editor</p>;
return (
<div>
<form>
<Editor
initialValue={content}
init={{ plugins: 'link image code',
toolbar: 'undo redo | bold italic| alignleft aligncenter alignright | code'}}
onChange={this.handleEditorChange}/>
<div className="col-md-3">
<button className="btn btn-block btn-primary btn-lg" type="submit">Save Event</button>
</div>
</form>
</div>
)}
}
我正在尝试使用 React js 从 tinyms
编辑器渲染它在控制台中显示未定义的数据。我想使用 React js 向 tinyms
编辑器写入一些内容。请帮我解决这个问题..
import React, { Component } from 'react';
import { Editor } from '@tinymce/tinymce-react';
class AddEvent extends Component {
constructor() {
super();
this.state = {
content: '',
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this.content);
}
render() {
return (
<form>
<Editor
initialValue="<p>This is the initial content of the editor</p>"
init={{ plugins: 'link image code',
toolbar: 'undo redo | bold italic| alignleft aligncenter alignright | code'
}}
onChange={this.handleEditorChange}
/>
<div className="col-md-3">
<button className="btn btn-block btn-primary btn-lg" type="submit">Save Event</button>
</div>
</form>
函数绑定类似于 .bind(this)
,但您绑定 handleEditorChange
的值不正确
改变
this.handleEditorChange = this.handleEditorChange.bind(this.content);
至
this.handleEditorChange = this.handleEditorChange.bind(this);
请在下面找到更正后的代码以及其他更改。这将按预期工作
import React, { Component } from 'react';
import { Editor } from '@tinymce/tinymce-react';
class AddEvent extends Component {
constructor() {
super();
this.state = {
content: '',
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this);
}
handleEditorChange(e){
console.log('Content was updated:', e.target.getContent());
this.setState({content: e.target.getContent()});
}
render() {
const content = <p>This is the initial content of the editor</p>;
return (
<div>
<form>
<Editor
initialValue={content}
init={{ plugins: 'link image code',
toolbar: 'undo redo | bold italic| alignleft aligncenter alignright | code'}}
onChange={this.handleEditorChange}/>
<div className="col-md-3">
<button className="btn btn-block btn-primary btn-lg" type="submit">Save Event</button>
</div>
</form>
</div>
)}
}