键入仅显示所有建议的第一个字符

时间:2017-06-23 09:56:10

标签: javascript jquery typeahead.js autosuggest bootstrap-tags-input

我是typeahead.js的新手。

我正在制作taginput + typahead:

我做得很好,但我遇到的问题只出现了第一个建议字符。

$('#name_t1').tagsinput({
  typeahead: {                  
    source: function(query) {
      return $.get('<?php echo base_url('search/search_player') ?>');
    }
  }
}); 

代码工作正常但我不知道为什么只有单个字符弹出。 请帮忙。

Screenshot

包括:

<script src="<?php echo VENDOR."custom/bootstrap-typeahead.js"; ?>"></script>
<script src="<?php echo VENDOR."custom/bootstrap-tagsinput.js"; ?>"></script>

<div class="col-md-12 input-group pull-left">
                            <span class="input-group-addon">Players:</span>
                            <input type="text" id="name_t1" value="" class="form-control" autocomplete="off">
                        </div>

                        <div class="col-md-12 m-t-xs">
                        <hr>
                            <div class="col-md-6"><input type="text" placeholder="Unpaid" tabindex="7" class="form-control error"></div>
                            <div class="col-md-6"><input type="text" placeholder="Paid" tabindex="8" class="form-control green"></div>
                        </div>

控制器:

public function search_player()
    {
        //header("Content-type: application/json");
        $term = $this->input->post('query');
        $query  = $this->player_model->get_player($term);
        $data = array();
        foreach ($query as $key => $value) 
        {
            $data[] = array('name' => $value->name);
        }

        echo json_encode($data);
    }

型号:

function get_player($term)
    {

        $query = 
            $this->db->select('id')
             ->select('name')
             ->from('player_list')
             ->like('name', $term)
             ->get();
        return $query->result();
        //$query = $this->db->get('player_list');
        //return $query->result();
    }

0 个答案:

没有答案