TinyMCE: Generate dynamic listbox options list

南笙酒味 提交于 2019-12-11 10:15:58

问题


I'm developping a plugin for TinyMCE and I want to have a listbox on which the user can select an option to insert in the editor.

This option list is not always the same, it depends on actions made on the website. The values are stored in an array that I successfully pass to the plugin.

I process the array to format it as an options list:

Object.keys(variablesArray).forEach(function (key) {
    parametersText = parametersText + "{text: '" + variablesArray[key] + "', value: '{{" + key + "}}'},";
});

The result is good. Then I want to declare it in my listbox:

editor.windowManager.open({
            title: 'Insérer variable',
            body: [
                {
                    type: 'listbox', 
                    name: 'list_variables', 
                    label: 'Sélectionnez une variable', 
                        'values': [
                            {text: 'Numéro de dossier', value: '{{id}}'},
                            {text: 'Date de l\'accident', value: '{{date_case}}'},
                            {text: 'Heure de l\'accident', value: '{{time_case}}'},
                            {text: 'Lieu de l\'accident', value: '{{case_address_1}}, {{case_address_2}}, {{case_postcode}}, {{case_city}}, {{case_country}}'},
                            {text: 'Description de l\'accident', value: '{{case_description}}'},
                            {text: 'Date de l\'accident', value: '{{date_case}}'},
                            parametersText,
                            {text: '', value: '{{}}'}
                ]}
            ],

But I get the following error: Uncaught Error: Could not find control by type: {text: '1', value: '{{id}}'},{text: 'mon test', value: '{{test}}'},

That shows me that it expects a proper option and not a var. Any idea how to fix that ?

Thanks in advance for your time.

来源:https://stackoverflow.com/questions/31562081/tinymce-generate-dynamic-listbox-options-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!