1

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.

Afroza Yasmin
  • 511
  • 1
  • 4
  • 22

1 Answers1

2

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
        });
    }
};
leninhasda
  • 1,620
  • 11
  • 18