Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON format for jquery-select2 multi with ajax
    primarykey
    data
    text
    <p>I'm thinking in moving from Chosen to Select2 because Select2 has native methods for ajax. Ajax is critical because usualy you have to load a lot of data. </p> <p>I executed sucessfully the example with the JSON of api.rottentomatoes.com/api/</p> <p>I did a JSON file to test the ajax, but it didn't works.</p> <p>I don't know how the JSON should be. It seems that there is no detailed documentation:</p> <p><a href="https://github.com/ivaynberg/select2/issues/920">https://github.com/ivaynberg/select2/issues/920</a></p> <p>I tried unsucessfully several JSON formats, so I tried to copy a JSON format similar to api.rottentomatoes but it doesn't works. </p> <p>I may be missing something stupid.</p> <pre><code>function MultiAjaxAutoComplete(element, url) { $(element).select2({ placeholder: "Search for a movie", minimumInputLength: 1, multiple: true, ajax: { url: url, dataType: 'jsonp', data: function(term, page) { return { q: term, page_limit: 10, apikey: "z4vbb4bjmgsb7dy33kvux3ea" //my own apikey }; }, results: function(data, page) { return { results: data.movies }; } }, formatResult: formatResult, formatSelection: formatSelection, /*initSelection: function(element, callback) { var data = []; $(element.val().split(",")).each(function(i) { var item = this.split(':'); data.push({ id: item[0], title: item[1] }); }); //$(element).val(''); callback(data); }*/ }); }; function formatResult(node) { return '&lt;div&gt;' + node.id + '&lt;/div&gt;'; }; function formatSelection(node) { return node.id; }; /*MultiAjaxAutoComplete('#e6', 'http://api.rottentomatoes.com/api/public/v1.0/movies.json');*/ MultiAjaxAutoComplete('#e6', 'https://raw.github.com/katio/Quick-i18n/master/test.json'); $('#save').click(function() { alert($('#e6').val()); }); </code></pre> <p>I did this jsfiddle:</p> <p><a href="http://jsfiddle.net/Katio/H9RZm/4/">http://jsfiddle.net/Katio/H9RZm/4/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload