@Pazzetif

Как Вывести из ajax массив в плагин ckeditor?

Имеется вот такой плагин.
/**
 * 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 );
                    }

                };
            } );
        }
    });

В нем есть ajax запрос, который получает нужные мне данные. Проверял в ajax console.log(), все данные принимает правильно. Так, как мне нужно, вот:
5b5599b1eee8a025154375.png
То что закомментировано сейчас, то как было раньше и откуда он брал нужные значения. Как мне сейчас брать значения из success? А именно вот это:
data[key][1] 
data[key][0]

Желательно кодом помочь, уже весь мозг вскипел(
  • Вопрос задан
  • 184 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы