I'm currently utilizing tinymce along with tinymce-variable. My goal is to create a dropdown menu with dynamic menu items generated from an SQL database. Through a loop, I've managed to successfully create multiple dropdown menus by using editor.addMenuItem()
for each menu item.
for(i=0;i<data.length;i++)
{
template_var = data[i]['variable'];
text_val = template_var.replace(/\s/g , " ");
editor.addMenuItem(template_var,
{
text : text_val,
context : 'newmenu',
onclick : function ()
{
editor.plugins.variable.addVariable(template_var);
}
})
}
The issue I'm encountering is that when I click on any menu item, it adds the last menu item to the editor instead of the specific menu item I clicked on. It seems like it's overwriting the
editor.plugins.variable.addVariable(template_var);
with the last menu item for all menu items. How can this be possible?
Thank you in advance.