反应HTML编辑器(TinyMce) [英] React HTML Editor (TinyMce)

查看:123
本文介绍了反应HTML编辑器(TinyMce)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为React搜索HTML编辑器,但是因为我发现没有什么能正常工作(我只需要格式化文本h1,h2,h3,p,粗体和图像[在base64中])

I was searching for an HTML Editor for React, but since I found nothing that works fine (I just need to format Text h1, h2, h3, p, bold and images [in base64])

最后我决定使用Tiny Mce,效果很好。但只有当页面第一次打开时。如果我再次访问该页面。如果没有浏览器关联,则不会初始化tinymce。你知道在这种情况下会发生什么反应事件。到目前为止,这是我的小包装器:

At the end I decided to use Tiny Mce, which works fine. But only when the page gets opened for the first time. If I get to that page again. Without a browser relaod, then tinymce is not initialized. Do you know what react event will be triggered in such a situation. Here is my little wrapper so far:

/** @jsx React.DOM */
var React = require('react');

var TinyMceEditor = React.createClass({
    componentDidMount: function() {
        var that = this;
        tinymce.init({
            selector: "textarea.tiny-mce-editor",
            setup : function(editor) {
                editor.on('change', function(e) {
                    that.props.onChange(editor.getContent());
                });
            },
            plugins: [
                "lists link image charmap print preview anchor",
                "searchreplace code fullscreen",
                "insertdatetime media table contextmenu paste"
            ],
            toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
        });
        tinyMCE.get(that.props.lang + '-editor').setContent(that.props.html);
    },
    render:function(){
        return (
            <div>
                <textarea ref="text" className="tiny-mce-editor" id={this.props.lang + '-editor'} />
            </div>
        )
    }
});
module.exports = TinyMceEditor;


推荐答案

要解决这个问题,我必须删除TinyMce实例卸载。

To fix this I had to delete the TinyMce instance when unmounting.

componentWillUnmount: function() {
    tinymce.remove('#' + this.props.lang + '-editor');
}

这篇关于反应HTML编辑器(TinyMce)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆