0

I am trying to develop a wordpress plugin and for it I need to add tinymce listbox with dynamic values. At the moment I have stored dynamic objects in listv array and I need to push them in to tinyMCE.activeEditor.settings.myKeyValueList. But it wont work. even I have tried push and valueOf javascript methods but still no luck.

function getValues() {
    //Set new values to myKeyValueList 
    var listv = [];
    var len = pw_script_vars.ad;
    for (i = 0; i < len.length; i++) {
        listv[i] = {
            text: pw_script_vars.ad[i],
            value: pw_script_vars.ad[i]
        };
    }
    for (i = 0; i < listv.length; i++) {
        tinyMCE.activeEditor.settings.myKeyValueList += [listv[i]];
    }

    return tinyMCE.activeEditor.settings.myKeyValueList;
}
Rajika Nanayakkara
  • 658
  • 1
  • 6
  • 11

1 Answers1

3

From what I have seen by searching for tinyMCE myKeyValueList, it seems like you have to simply assign the value

tinyMCE.activeEditor.settings.myKeyValueList = listv;

instead of trying to add to it:

for (i = 0; i < listv.length; i++) {
    tinyMCE.activeEditor.settings.myKeyValueList += [listv[i]];
}

If you want to append to the existing myKeyValueList array (if it actually exists), see How to extend an existing JavaScript array with another array, without creating a new array? .

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143