我的自动填充功能无法在codeigniter中运行

问题描述 投票:0回答:1

即使我的chrome调试器 - > network - >显示正确的结果,自动完成功能也无法在codeigniter中运行。这是我的视图文件代码:

<input type="text" class="form-control select_group product" style="text-transform: uppercase;" id="gang" name="gang" placeholder="Gangman Name" autocomplete="off" >
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">            
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$( "#gang" ).autocomplete({
source: "<?php echo base_url('Issue/getGangName/?');?>",
minLength: 3
});
});
</script>

这是我的控制器功能

public function GetGangName()
{
  $this->load->model('Issuemodel');
  $gangdata=$this->Issuemodel->GetGang();        
  echo json_encode($gangdata);
}
php jquery jquery-ui jquery-ui-autocomplete
1个回答
0
投票

根据jQuery UI Autocomplete's docs,您的PHP处理程序应返回具有以下形式的数据:

[
  "NARAYAN SINGH CHUNDAWAT MLS",
  "RADHESHYAM SARGRA RMCH 2",
  // ...
]

或者这样的形式:

[
  { "label": "some label", "value": "NARAYAN SINGH CHUNDAWAT MLS" },
  { "label": "some label", "value": "RADHESHYAM SARGRA RMCH 2" },
  // ...
];
// Note: should work with only the "value" key if you don't need the labels

使用原始数据的示例(我刚刚更改了相关的代码块):

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $("#gang").autocomplete({
      source: [{
        "value": "NARAYAN SINGH CHUNDAWAT MLS"
      }, {
        "value": "RADHESHYAM SARGRA RMCH 2"
      }, {
        "value": "TRILOK CHANDRA SUTHAR RMCH 2"
      }, {
        "value": "ASLAM KHAN"
      }, {
        "value": "BHARAT SINGH"
      }, {
        "value": "Bhrth Raj Mehta RMCH 2"
      }, {
        "value": "CHANDRA PAL SINGH"
      }, {
        "value": "Deepak sharma"
      }, {
        "value": "DEVI LAL KACHI"
      }, {
        "value": "GAANGA SINGH RATHORE"
      }],
      minLength: 3
    });
  });
</script>

<input type="text" class="form-control select_group product" style="text-transform: uppercase;" id="gang" name="gang" placeholder="Gangman Name" autocomplete="off">
© www.soinside.com 2019 - 2024. All rights reserved.