title: can't template select2 plugin accordingly
body: <p>i need to template the jquery Select2 plugin results, but i can't seem to get my custom variables to be recognized.
  my Select2 configuration:</p>
  
  <pre><code>$('.idWorker').select2(
      {
         templateResult: formatWorker  
      }
  );
  </code></pre>
  
  <p>My formatWorker function:</p>
  
  <pre><code>function formatWorker (worker) {
  console.log(worker);
  var markup = worker.id+'&lt;p&gt;'+
  worker.name+'&lt;p&gt;'+
  worker.available+'&lt;p&gt;';
  return markup;
  }
  </code></pre>
  
  <p>PHP that generates workers data:</p>
  
  <pre><code>public function get($id = null)
  {
      if($id != null)
      $this-&gt;db-&gt;where("id = {$id}");
      $query = $this-&gt;db-&gt;get('worker');
      if($query-&gt;num_rows() &gt;= 1)
      {
          return $query-&gt;result();
      }
  }
  </code></pre>
  
  <p>PHP that generates select2 data:</p>
  
  <pre><code>public function customSelect2()
  {
      $array = array();
      foreach ($this-&gt;get() as $worker)
      {
         $this-&gt;db-&gt;select("count(tkal.id) as resultcount from token_allocate tkal
          left join worker w on w.id = tkal.idWorker
          where tkal.idWorker = {$worker-&gt;id}");
          $query = $this-&gt;db-&gt;get()-&gt;result()[0];
          $available = ($query-&gt;resultcount &gt;= 1) ? "this person has been called to attend to {$query-&gt;resultcount} tokens" : 'this person is available';
         $array[] = array('id' =&gt; $worker-&gt;id,'name' =&gt; $worker-&gt;name, 'available' =&gt; $available); 
      }
      return $array;
  }
  </code></pre>
  
  <p>that's the strange part, in my js console log, for each worker it prints the following:</p>
  
  <pre><code>Object {selected: false, disabled: false, text: "22", id: "id", title: ""…}
  Object {selected: false, disabled: false, text: "Moisés Adriano Lago de   Almeida", id: "name", title: ""…}
  Object {selected: false, disabled: false, text: "this person is available", id: "available", title: ""…}
  </code></pre>
  
  <p>Why does it create 3 objects for each one and single work in database? i mean, look at what my console prints about the formatWorker function.
  <br>
  AND
  <br>
  Why i cant use the variables that i set in php like this?</p>
  
  <pre><code>var markup = worker.id+'&lt;p&gt;'+
  worker.name+'&lt;p&gt;'+
  worker.available+'&lt;p&gt;';
  return markup;
  </code></pre>