I've been Kolupa already for a long time, izlazil all that is possible. But it does not work There is a ckeditor plugin. It statically displays information in the form of select. It works something like this: enter image description here

Here is the code for this site:

id : 'hero', type : 'select', label : 'Выбери имя.', items: [ [ 'Mamba', '1'],[ 'Lamba', '2'] ], 'default': '', onChange: function( api ) { // this = CKEDITOR.ui.dialog.select alert( 'Current value: ' + this.getValue() ); } 

Here we list the name and, when selected, we get its value. Hike instead of this:

 function( api ) { // this = CKEDITOR.ui.dialog.select alert( 'Current value: ' + this.getValue() ); } 

I need an ajax request. Actually, in items I need values ​​from ajax.

 $.ajax({ url: '/heroes', success: function(data) { for (var key in data) { // data[key][1] data[key][0] - примерно такого вида. } 

File: heroes.php: I do not know where to put the php code. So so .. https://codepen.io/anon/pen/zLwYjP

HeroesController.php: https://codepen.io/anon/pen/bjWGjV

It is necessary that the value of $ array [$ k] [] = $ heroes-> name; so the html code is also the one that in $ array [$ k] [] in the data key and data [key] [0] I hope I was able to convey the thought, I was already desperate ...

2 answers 2

In the request, specify

 dataType: 'json' 

In heroes.php, output an array like

 echo json_encode($array); 

    Maybe someone will come in handy, did this:

     jQuery.extend({ getValues: function(url) { var result = null; $.ajax({ url: url, type: 'get', dataType: 'json', async: false, success: function(data) { result = data; console.log(result) } }); return result; } }); var results = $.getValues('/heroes'); CKEDITOR.plugins.add( 'hero', { icons: 'hero', requires : ['richcombo'], //, 'styles' ], init : function( editor ) { editor.addCommand( 'abbrDialog', new CKEDITOR.dialogCommand( 'abbrDialog' ) ); editor.ui.addButton( 'Hero', { label: 'Выбрать героя', command: 'abbrDialog', } ); CKEDITOR.dialog.add( 'abbrDialog', function ( editor ) { return { title : 'Выбор героя', minWidth : 400, minHeight : 200, contents : [ { id : 'tab1', label : 'Tenants', elements : [ { type : 'select', id : 'style', label : 'Style', setup : '', items : results, commit : function( data ) { data.style = this.getValue(); } } ] } ], onOk : function() { var dialog = this; var abbr = editor.document.createElement( 'span' ); abbr.setHtml( dialog.getValueOf( 'tab1', 'style' ) ); editor.insertElement( abbr ); } }; } ); } });