Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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;
}
share|improve this question
1  
Please post your attempt with .push(). += is definitely wrong. –  Felix Kling 2 days ago
    
its something like this for(i=0; i < listv.length; i++){ tinyMCE.activeEditor.settings.myKeyValueList.push([listv[i]]); } –  Rajika Nanayakkara 2 days ago
    
i assume += is wrong but as i said in the description push() also did not work –  Rajika Nanayakkara 2 days ago
add comment

1 Answer

up vote 3 down vote accepted

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 append an array to an existing JavaScript Array? .

share|improve this answer
    
thanx mate it works.. i was trying to fix this for almost 5 hours.. thank you you saved my day...! –  Rajika Nanayakkara 2 days ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.