dongzhi6382 2017-04-01 03:09
浏览 38

CodeIgniter:在JSON列表中选择相同的参数

I'm trying to use tokeninput from jQuery Token input, but the data is from the API. I already got the data from API and made a JSON list (see below).

When a user inputs in my token input, it will select from the JSON list, like user/auto_unit?queryParam=q for example. It already gets the user input correctly, but it still returns all data, even those that do not match the user input.

What I want is when the user searches for "Sosiologi", the only values that would show are those string which have "sosiologi" in them.

Is it possible to get only the same values and how can I do that? Thanks in advance!

My JSON list:

// 20170401095401
// http://exp.uin-suka.ac.id/aspirasi/user/auto_unit?queryParam=Filsafat%20Agama

[
  {
    "id": "UA000001",
    "name": "Filsafat Agama"
  },
  {
    "id": "UA000002",
    "name": "Perbandingan Agama"
  },
  {
    "id": "UA000003",
    "name": "Ilmu Al-Qur'an dan Tafsir"
  },
  {
    "id": "UA000004",
    "name": "Sosiologi Agama"
  },
  {
    "id": "UA000005",
    "name": "Matematika"
  },
  {

My JSON code to get the list

function auto_unit() {  
    $data['unit'] = $this->m_simpeg->getAllUnit();
    foreach ($data['unit'] as $key ){
        $row['id']= $key['UNIT_ID'];
        $row['name']= $key['UNIT_NAMA'];
        $row_set[] = $row;
    }
    echo json_encode($row_set);
}

Model to get API M_simpeg.php:

public function getAllUnit(){
    return $this->s00_lib_api->post_api(
        1001, 1, null,
        URL_API_SIMPEG.'simpeg_mix/data_view'
    );
}
  • 写回答

1条回答 默认 最新

  • douzhong2954 2017-04-01 06:12
    关注

    Check your server side code as it is not filtering the array. Codeigniter sample code

    <?php
    function filter(){
    $queryParam=$this->input->get('queryParam');
    $res=$array.filter($queryParam);
    return $res;
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题