【问题标题】:Tinymce dynamically generated icon listTinymce 动态生成的图标列表
【发布时间】:2012-05-31 19:44:58
【问题描述】:

我正在尝试为小 mce 创建动态生成的图标列表。我已经编写了所有相关的 php 函数,我通过以下代码调用该函数。

$.post(url_file, { 
       content_name: $class_name, 
       page_url: filePath,
       app_code: app_code
   },
   function(data){
       var buttonlist = data;
   });

我需要传递以上 3 个参数才能获得这些图标。现在我有 buttonlist 。我尝试了document.write(buttonlist),但它给了我missing : after property id 错误。 我想在里面打印这个;

tinyMCE.init({
        mode : "exact",
        elements : "elm1", 
        theme : "advanced",
        plugins : "Archiv,pagebreak,safari,spellchecker,pagebreak,
                   style,layer,table,save,advhr,advimage,advlink,
                   emotions,iespell,inlinepopups,insertdatetime,preview,
                   media,searchreplace,print,contextmenu,paste,
                   directionality,fullscreen,noneditable,visualchars,nonbreaking,
                   xhtmlxtras,template",
    --> document.write(buttonlist);
        theme_advanced_toolbar_location : "top",

您知道如何在 tinymce 代码中打印此值吗? 非常感谢帮助。

【问题讨论】:

    标签: php jquery tinymce document


    【解决方案1】:

    您需要动态添加按钮吗?

    试试这个:

    要获取它,请为每个按钮行使用 json:

    $.post(url_file, { 
       content_name: $class_name, 
       page_url: filePath,
       app_code: app_code
    },
    function(data){
       var buttons = $.parseJSON(data)
       var buttonlist1 = buttons.line1;
       var buttonlist2 = buttons.line2;
       var buttonlist3 = buttons.line3;
    });
    

    然后进行 MCE 初始化:

    tinyMCE.init({
        mode : "exact",
        elements : "elm1", 
        theme : "advanced",
        plugins : "Archiv,pagebreak,safari,spellchecker,pagebreak,
                   style,layer,table,save,advhr,advimage,advlink,
                   emotions,iespell,inlinepopups,insertdatetime,preview,
                   media,searchreplace,print,contextmenu,paste,
                   directionality,fullscreen,noneditable,visualchars,nonbreaking,
                   xhtmlxtras,template",
    --> theme_advanced_buttons1 : buttonlist1,
    --> theme_advanced_buttons2 : buttonlist2,
    --> theme_advanced_buttons3 : buttonlist3,
        theme_advanced_toolbar_location : "top",
    

    【讨论】:

    • 您好,感谢您的回答。我尝试过这个。但是随后tinymce没有加载一定有问题。但我看不出 json 数据有什么问题。当我alert(buttonlist2); 时,它会提醒正确的图标。
    • 啊哈哈!有效!我把tinyMCE.init()放在function(data){里面谢谢duuuuuuude!
    【解决方案2】:

    当使用 php 创建页面时,php 代码会在页面交付给客户端之前首先执行。因此,您可以执行以下操作:

    <?php
        $my_generated_buttonlist = '"bold, italic, underline"';
    ?>
    
    tinyMCE.init({
    
        mode : "exact",
    
        elements : "elm1", 
    
        theme : "advanced",
    
        plugins : "Archiv,pagebreak,safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
    
        theme_advanced_buttons1: '<?php echo $my_generated_buttonlist; ?>',
    
        theme_advanced_toolbar_location : "top",
        ...
    

    【讨论】:

    • 我无法将我的值放入 php 变量中,这就是为什么我坚持这一点。我从数据库中获取这些图标,所以我必须查询它,我的 php 函数在查询后生成这些图标列表。但是要查询它,我需要将我传递给 $.post 的变量传递给。
    • 好吧,我解决了这个问题,我只有一个解决方案,我将内容写入文件并回显文件内容。但我还有另一个问题。我在一个文件中有几个不同的文本区域,我想在每个 tinymce 实例上显示不同的图标。当我使用我的解决方案时,它总是加载它加载的第一个。很明显..对此有任何解决方案的想法吗?
    猜你喜欢
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 2015-04-30
    • 2011-10-18
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多