select2 Loading remote data
Всем привет. Не могу запустить Loading remote data из примера
<!DOCTYPE HTML> <html> <title>Untitled</title> <meta charset="utf-8"> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <link href="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-beta.3/css/select2.min.css" rel="stylesheet" /> <script src="http://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0-beta.3/js/select2.min.js"></script> <style> .selectRow { display : block; padding : 20px; } .select2-container { width: 200px; } </style> <script> $( document ).ready(function() { $(".js-data-example-ajax").select2({ ajax: { url: "https://api.github.com/search/repositories", dataType: 'json', delay: 250, data: function (params) { return { q: params.term, // search term page: params.page }; }, processResults: function (data, page) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to // alter the remote JSON data return { results: data.items }; }, cache: true }, escapeMarkup: function (markup) { return markup; }, // let our custom formatter work minimumInputLength: 1, templateResult: formatRepo, // omitted for brevity, see the source of this page templateSelection: formatRepoSelection // omitted for brevity, see the source of this page }); }); </script> </head> <body> <body> <select class="js-data-example-ajax"> <option value="select2/select2" selected="selected">select2/select2</option> </select> </body> </body> </html> Он так будет работат? в консоле ошибка Uncaught ReferenceError: formatRepo is not defined в чем проблема? |
с этим разобрался.
Еще один вопрос. Делаю запрос ajax var formatProduct = function(data){ return '<div>'+(data.city)+'</div>'; } $("#city").select2({ ajax: { url: "ajaxdata", dataType: 'json', data: function (params) { return { country_id: country, term: params.term }; }, results: function (data) { return { results: data.items, }; } }, templateResult: formatProduct, }); json данные "items":[{"id":2131,"city":"\u0410\u0442\u044b\u0440\u0430\u0443"},{"id":5427176,"city":"\u0410\u0442\u044b\u0440\u0430\u0443 \u0441\u0435\u043b\u043e"}]} как мне вернуть city из json? что опят делаю не так. |
Цитата:
|
Цитата:
|
Часовой пояс GMT +3, время: 06:07. |