Reactjs 如何在react js中从tinymc编辑器中获取值?
我正在尝试从Reactjs 如何在react js中从tinymc编辑器中获取值?,reactjs,react-redux,textarea,editor,contenteditable,Reactjs,React Redux,Textarea,Editor,Contenteditable,我正在尝试从tinyms编辑器渲染数据,该编辑器使用react js在控制台中显示未定义的数据。我想使用react js将一些内容写入tinyms编辑器。请帮我解决这个问题 import React, { Component } from 'react'; import { Editor } from '@tinymce/tinymce-react'; class AddEvent extends Component { constructor() { super()
tinyms
编辑器渲染数据,该编辑器使用react js在控制台中显示未定义的数据。我想使用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>
import React,{Component}来自'React';
从'@tinymce/tinymce-react'导入{Editor};
类AddEvent扩展组件{
构造函数(){
超级();
此.state={
内容:“”,
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this.content);
}
render(){
返回(
保存事件
函数绑定类似于.bind(this)
,但您正在使用不正确的值绑定handleEditorChange
改变
this.handleEditorChange = this.handleEditorChange.bind(this.content);
到
请找到下面更正的代码以及其他更改。这将按预期工作
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>
)}
}
import React,{Component}来自'React';
从'@tinymce/tinymce-react'导入{Editor};
类AddEvent扩展组件{
构造函数(){
超级();
此.state={
内容:“”,
};
this.handleChange=this.handleChange.bind(this);
this.handleEditorChange=this.handleEditorChange.bind(this);
}
手部编辑或更改(e){
log('内容已更新:',e.target.getContent());
this.setState({content:e.target.getContent()});
}
render(){
const content=这是编辑器的初始内容;
返回(
保存事件
)}
}
this.handleChange=this.handleChange.bind(this);正如你在这里观察到的,如果我这样给出的话。handleEditorChange=this.handleEditorChange.bind(this);它在控制台中显示未定义。但是内容是以html标记的形式出现的…如何删除html标记..你能帮我解决这个问题吗..@Think-Twice@AvinashMaddala我已经更新了我的答案,请现在试一试。既然你已经接受了我的答案,请不要犹豫。是的,我同意你的答案,但我需要另一个帮助。数据仍然是我要的是html标记。我希望它像正确的内容一样。@AvinashMaddala请在没有html标记的情况下呈现它。
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>
)}
}