【问题标题】:Dynamic data added in custom TinyMCE Editor using AngularJs使用 AngularJs 在自定义 TinyMCE 编辑器中添加动态数据
【发布时间】:2016-08-04 09:39:14
【问题描述】:

我正在使用 anglarjs TinyMCE 编辑器https://www.tinymce.com/docs/integrations/angularjs/,在这里,我在工具箱中添加了自定义下拉按钮,当我使用静态值时它工作正常,但我实际上不知道如何在其中加载动态数据值下拉列表。

setup : function ( editor ) {
             editor.addButton( 'customDrpdwn', {
                text : 'Customers List',
                type: 'menubutton',
                icon : false,
                menu: [
                  {
                    text: 'Customer 1',
                    onclick: function(){
                      alert("Clicked on Customer 1");
                    }
                  },
                  {
                    text: 'Customer 2',
                    onclick: function(){
                      alert("Clicked on Customer 2");
                    }
                  }
                ]

            });
        }, 
  }; 

我尝试自己在菜单文本字段中加载动态值,但出现错误。像这样动态加载我的代码后 -

$scope.customerList = ['Customer 1','Customer 2'];
setup : function ( editor ) {
     editor.addButton( 'customDrpdwn', {
        text : 'Customers List',
        type: 'menubutton',
        icon : false,
        for(var i =0; i< $scope.customerList.length; i++){
          menu: [
            {
              text: $scope.customerList[i],
              onclick: function(){
                alert("Clicked on Customer 1");
              }
            }
          ]
        }
    });
} 

现在,我的问题是,可以在此自定义字段中加载动态数据。如果是这样,那么我如何动态加载数据?请帮帮我。

【问题讨论】:

  • 你有什么控制台错误?
  • 使用 tinymce 编辑器的 onPostRender 属性
  • 好的,我收到了 SyntaxError 和一些 angularjs 错误。
  • @uzaif 怎么用进去?
  • 你可以这样使用onPostRender: function() { var ctrl = this; $.getJSON( url , function( menu) { ctrl.state.data.menu = ctrl.settings.menu = menu; }); }

标签: javascript angularjs tinymce


【解决方案1】:

这是一种方法:

$scope.customerList = ['Customer 1','Customer 2'];
// first make all the menu items
var menuItems = [];
$scope.customerList.forEach(function(customer, index){
    item = {
        'text': customer,
        onclick: function(){
            alert("Clicked on " + customer);
        }
    };
    menuItems.push(item);
});

$scope.tinymceOptions = {
    plugins: 'link image code',
    toolbar: 'undo redo | bold italic | alignleft aligncenter alignright | code | customDrpdwn',
    setup: function(editor){
        editor.addButton( 'customDrpdwn', {
            text : 'Customers List',
            type: 'menubutton',
            icon : false,
            menu: menuItems // then just add it here
        });
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 2017-01-17
    相关资源
    最近更新 更多