Tinymce:在输入时添加新段落时不要复制类

时间:2017-07-29 17:59:13

标签: javascript tinymce-4

使用自定义按钮,我添加了一个包含类和一些内容的paragraphe,如下所示:

<p class="mce-new-class">my custom content</p>

当我在这样的段落后按Enter键时,TinyMCE将使用完全相同的类自动添加新段落:

<p class="mce-new-class">my custom content</p>
<p class="mce-new-class">&nbsp;</p>

我想只有一个新段落,但没有班级:

<p class="mce-new-class">my custom content</p>
<p>&nbsp;</p>

我试过这个:

tinymce.init({
    ...
    setup: function (ed) {
        ed.on('keydown',function(e) {
            if(e.keyCode == 13){
                ed.selection.setContent('<p>&nbsp;</p>'); 
                return false;
            }
        });
    }
});

但这适用于所有情况,并会制止其他有用的情况,例如在“输入按下”复制列表元素

非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

找到解决方案:

import React, {Component} from 'react';
            import axios from 'axios';
            import loading from '../loading.gif' // relative path to image

            class Home extends Component {
                constructor() {
                    super()
                    this.state = {
                        time: null,
                        loading: true,
                        retJobs: []
                    }
                    this.getJobs();

                }

                getJobs() {


                    axios.get('http://example.com/getData.php')
                        .then(response => {
                            this.setState({retJobs: response.data});
                            console.log(response);

                            console.log(this.state.retJobs.results.length);
                            console.log(this.state.retJobs.results);
                            this.setState({
                                time: response.data.time,
                                loading: false
                            });
                        })
                        .catch(function (error) {
                            console.log(error);
                        });

                }


                render() {

                    let content;

                    if (this.state.loading) {
                        content = <img src={loading} alt="loading"/>// or another graceful content
                    } else {
                        content = <p className="jobCount">Found {this.state.retJobs.results.length} Jobs</p>;
                    }

                    return (


                        <div>
                            <h4>Home</h4>
                            <div className="App-intro">
                                <div className="container">
                                    <div className="row mainContent">
                                        <div className=" row mainContent">
                                            {content}
                                            {this.state.retJobs.results && this.state.retJobs.results.map(function (item, idx) {
                                                return <div key={idx} className="col-lg-12">
                                                    <div className="jobs">
                                                        <div className="row jobHeader">

                                                            <div className="col-lg-6">
                                                                <h1>{item.jobTitle}</h1>
                                                            </div>
                                                            <div className="col-lg-6">
                                                                <h3>{item.locationName}</h3>
                                                            </div>
                                                        </div>
                                                        <div className="row">

                                                            <div className="col-lg-2">
                                                                <h2>{item.employerName}</h2>
                                                            </div>
                                                            <div className="col-lg-10">
                                                                <p>{item.jobDescription}</p>
                                                            </div>


                                                        </div>
                                                    </div>
                                                </div>
                                            })}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    );
                }
            }

            export default Home;