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.

5
  • what console error do you have? Commented Apr 13, 2016 at 10:52
  • use this onPostRender property of tinymce editor Commented Apr 13, 2016 at 10:55
  • okay, I'm getting SyntaxError and some angularjs error. Commented Apr 13, 2016 at 10:57
  • @uzaif how can I used into it? Commented Apr 13, 2016 at 10:58
  • you can use this way onPostRender: function() { var ctrl = this; $.getJSON( url , function( menu) { ctrl.state.data.menu = ctrl.settings.menu = menu; }); } Commented Apr 13, 2016 at 11:02

1 Answer 1

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
        });
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.