Answer the question
In order to leave comments, you need to log in
How to output an array from ajax to ckeditor plugin?
There is such a plugin.
/**
* Copyright (c) 2014-2018, CKSource - Frederico Knabben. All rights reserved.
* Licensed under the terms of the MIT License (see LICENSE.md).
*
* Basic sample plugin inserting current date and time into the CKEditor editing area.
*
* Created out of the CKEditor Plugin SDK:
* http://docs.ckeditor.com/ckeditor4/docs/#!/guide/plugin_sdk_intro
*/
// Register the plugin within the editor.
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 )
{
var fields;
var tenant_fields = []; //new Array();
$.ajax({
url: '/heroes',
success: function(data) {
for (var key in data)
{
$('.cke_dialog_ui_input_select select').html('<option value='+data[key][1]+'>'+data[key][0]+'</option>');
}
// '<a href="" data-html="true" data-trigger="hover" data-toggle="popover" data-content="rgdrg"><img src="/images/heroes_small/pudge_small.png" style="width: 26px; height: 15px; margin-top: 0; margin-right: 4px" alt="">'+data[key]+'</a>'];
}
});
// tenant_fields[4]=["Invoker", "4"];
// tenant_fields[5]=["Axe", "5"];
// tenant_fields[6]=["Juggernaut", "6"];
// tenant_fields[7]=["Bloodseeker", "7"];
// tenant_fields[8]=["Zeus", "8"];
// tenant_fields[9]=["Faceless Void", "9"];
// tenant_fields[10]=["Legion Commander", "10"];
// tenant_fields[11]=["Crystal Maiden", "11"];
return {
title : 'Выбор героя',
minWidth : 400,
minHeight : 200,
contents :
[
{
id : 'tab1',
label : 'Tenants',
elements :
[
{
id : 'tenant_dropdown',
type : 'select',
label : 'Выбери героя.',
'default':'',
items: tenant_fields
}
]
}
],
onOk : function()
{
var dialog = this;
var abbr = editor.document.createElement( 'span' );
abbr.setText( dialog.getValueOf( 'tab1', 'tenant_dropdown' ) );
editor.insertElement( abbr );
}
};
} );
}
});
data[key][1]
data[key][0]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question