初始化后设置 TinyMCE 编辑器选项

Set TinyMCE editor option after Initialization

初始化后如何设置TinyMCEtemplates选项?在 TinyMCE 4 中可以吗?

我在 Template plugin 的源代码中看到,每次用户单击 'Insert template' 按钮时都会读取此选项。所以我认为它可以在每次点击时获得一个新的价值。

ps. 一个可能的解决方案是在 templates 中使用 URL,但我们假装不是。

几天前我试过这样做 - 特别是在单击子菜单按钮时加载子菜单中的项目。听起来这是同样的问题。

除了销毁编辑器实例并使用修改后的配置再次调用 tinymce.init() 之外,我找不到执行此操作的方法。

更新: 在 TinyMCE v4.3.3 中更新了模板插件,因此 templates 设置可以是一个函数,该函数获取可以提供模板的回调。好消息,您不必修补插件 =)

初始化:

$scope.tinyMceOptions = {
    plugins: 'template',
    ...
    templates: function(callback) {
        // Here you can do whatever you want with callback;
        // for example, you can provide different arguments on every click
        callback($scope.variableTemplates);
    }

(对于以前的 TinyMCE 版本) 我的解决方案是修补模板插件,我可以指定一个函数作为模板提供程序。这是我添加到 createTemplateList() 函数的内容:

else if (typeof templateList === 'function') {
    callback(templateList());
}

并且在初始化期间我在 templates:

中指定了一个函数
$scope.tinyMceOptions = {
    plugins: 'template',
    ...
    templates: function() {
        return $scope.variableTemplates;
    }