tinyMCE似乎并不总是被初始化

时间:2016-11-08 02:35:24

标签: javascript jquery tinymce

我已经设置tinyMCE编辑器来设置初始化后的内容,我使用init_instance_callback来调用具有该目的的函数。问题是有时会调用该函数。我已经意识到,如果我通过开发人员工具在浏览器中禁用缓存,则始终调用该函数,否则仅在有时调用它。如果我多次访问同一页面,如何强制tinyMCE始终初始化并致电init_instance_callback

这是我的代码:

tinyMCE.init({
        selector: 'textarea.mceEditor', 
        plugins: 'powerpaste code textcolor link emoticons table print preview visualchars',
        powerpaste_word_import: 'prompt',
        powerpaste_html_import: 'prompt',
        powerpaste_allow_local_images: true,
        browser_spellcheck: true,
        fontsize_formats: "8pt 10pt 12pt 14pt 18pt 24pt 36pt",
        forced_root_block: false,
        toolbar1: 'forecolor backcolor undo redo styleselect bold italic alignleft aligncenter alignright alignjustify bullist numlist outdent indent',
        toolbar2: 'link fontsizeselect',
        paste_preprocess : function(pl, o) {
            o.content = o.content.replace(/(<\/p>)/gi,'<br/><br/>');
            o.content = o.content.replace(/(<p>)/gi,'');

        },
        init_instance_callback : "initAdvertDescription"

    });


function initAdvertDescription() {   

        console.log(advertDescription);
        tinyMCE.get(aspnetPrefix_Hash + "tbxDescription").setContent(advertDescription);
 }

1 个答案:

答案 0 :(得分:0)

更新:(编辑我的回答,我不知道init_instance_callback也是API v4的一部分)

您可以改为使用init

之类的tinymce.init({ ... setup: function(editor) { editor.on('init', function(e) { console.log('init event', e); editor.setContent(advertDescription); }); } }); 事件
  

编辑器初始化后触发。这是在编辑器填满内容之后。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>stormkafka_wordcount</groupId>
    <artifactId>stormkafka_wordcount</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.building.sourceEncoding>UTF-8</project.building.sourceEncoding>
        <java.version>1.7</java.version>
        <kafka.version>0.10.1.0</kafka.version>
        <storm.version>1.0.2</storm.version>
        <scala.version>2.11</scala.version>
        <hadoop.version>2.7.3</hadoop.version>
        <hbase.version>1.2.3</hbase.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm</artifactId>
            <version>${storm.version}</version>
        </dependency>

        <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-core</artifactId>
        <version>${storm.version}</version>
        <scope>provided</scope>
        </dependency>

    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka_${scala.version}</artifactId>
        <version>0.10.1.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.apache.zookeeper</groupId>
                <artifactId>zookeeper</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-kafka</artifactId>
        <version>${storm.version}</version>
    </dependency>
    </dependencies>
</project>

TinyMCE文档真是一团糟,根本不容易找到你想要的信息。此外,API版本3比版本4更好地引用了Google。请注意您正在阅读的文档版本,这两个版本之间有很多变化。

我个人更喜欢使用in the documentation来获得更清晰的文档。