Dynamic data added in custom TinyMCE Editor using AngularJs

放肆的年华 提交于 2021-01-28 07:29:06

问题


I am using anglarjs TinyMCE editor, https://www.tinymce.com/docs/integrations/angularjs/, here, I added custom dropdown button in toolbox, and Its working fine when I used static value,but I don't know actually how can I loaded dynamic data value in this dropdownlist.

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");
                    }
                  }
                ]

            });
        }, 
  }; 

I try myself to load dynamic value in Menu text field, but I'm getting error. After dynamic loading my code like this -

$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");
              }
            }
          ]
        }
    });
} 

Now, my question is that, this is possible to load dynamic data in this custom field. If so then how can I load data dynamically? Please help me.


回答1:


here is one way to do this:

$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
        });
    }
};


来源:https://stackoverflow.com/questions/36595911/dynamic-data-added-in-custom-tinymce-editor-using-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!