title: Select2 load JSON resultset via AJAX and search locally
body: <p>Until now I've been using Select2's normal AJAX method of searching and filtering data serverside, but now I have a usecase where I want to retrieve all the results via AJAX when the select is opened and then use those results (now stored locally) to search and filter. </p>
  
  <p>I've trawled the web looking for examples of how to do this and all i've found is lots of people saying the Query method should be used rather than the AJAX helper. Unfortunately I haven't found any examples.</p>
  
  <p>So far all I've managed is the basic:</p>
  
  <pre><code>$('#parent').select2({
    placeholder: "Select Parent",
    minimumInputLength: 0,
    allowClear: true,
    query: function (query) {
        //console.log(query);
        query.callback(data);
    }
  });
  
  data = {
   more: false,
   results: [
      { id: "CA", text: "California" },
      { id: "AL", text: "Alabama" }
   ]
  }
  </code></pre>
  
  <p>Data is being passed to the select but query filtering is not implemented.</p>
  
  <p>I'm struggling to understand the select2 documentation and would appreciate any assistance or links to examples.</p>