【问题标题】:Error when trying to use plugins in redactor yii2尝试在 redactor yii2 中使用插件时出错
【发布时间】:2017-08-30 08:55:44
【问题描述】:

我正在尝试创建一个示例插件,但出现此错误:

Uncaught ReferenceError: RedactorPlugins is not defined

这是我的插件代码:

<?php
    $script = <<< JS

   (function($)
    {
        $.Redactor.prototype.advanced = function()
        {
            return {
                init: function ()
                {
                    var button = this.button.add('advanced', 'Advanced');
                    this.button.addCallback(button, this.advanced.test);
                },
                test: function(buttonName)
                {
                    alert(buttonName);
                }
            };
        };
    })(jQuery);

JS;
$this->registerJs($script);
?>

我的高级插件是在 redactor.js 之后加载的,我应该修改什么来让 Redactor 接受插件?

提前致谢!

【问题讨论】:

    标签: yii2 redactor


    【解决方案1】:

    如果您通过浏览器查看 html 代码,我相信 JS 将在 Redactor 插件之前,也可能在 jquery 之前。 只需添加依赖项

    $this->registerJs($script,['depends' => [\yii\web\JqueryAsset::className()]]);
    

    然后检查您的代码在打印的 html 中的位置

    如果还在Redactor插件之前,你可以新建一个JS文件,添加到AppAsset.php中,就在Redactor插件下面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-08
      相关资源
      最近更新 更多