weixin_33692284 2016-03-21 05:26 采纳率: 0%
浏览 9

自动填充cakephp

I am trying to implement auto fill functionality in my application but it is not working. I have tried everything . I have also included necessary js and css files Please have a look at my code and suggest any changes. Controller:

    public function getfill($id=NULL)
{
    $this->autoRender = false;
    if($this->request->data['type'] == 'panels_table')
    {
        $name = trim( $this->data['name_startsWith'] );
        $result = $this->Panel->find('all', array('conditions'=>array('Panel.name LIKE'=>'%'.$name.'%')));
        $data = array();
        foreach ($result as $row)
        {
            $name = $row['Panel']['name'].'|'.$row['Panel']['designation'].'|'.$row['Panel']['specialization'].'|'.$row['Panel']['university'].'|'.$row['Panel']['college'].'|'.$row['Panel']['address'].'|'.$row['Panel']['phone'].'|'.'|'.$row['Panel']['email'];
            array_push($data, $name);
        }
        echo json_encode($data);
        exit;
    }

}

View:

     $('.pchange').each(function()
 {       
    var g=$(this).attr('id');
    //alert(g);
    var lastChar = g.replace ( /[^\d.]/g, '' );
    $('#name'+lastChar).autocomplete({
        source: function( request, response )
        {
            $.ajax({
            url : '<?php echo Router::url(array('controller'=>'Panels','action'=>'getfill'));?>',
            dataType: "html",
            method: 'post',
            data: {
            name_startsWith: request.term,
            type: 'panels_table',
            row_num : 1
            },
            success: function( data ) { 
                response( $.map( data, function( item ) {
                var code = item.split("|");
                return {
                    label: code[0],
                    value: code[0],
                    data : item
                }
            }));
        }
    });
    },
    autoFocus: true,            
    minLength: 1,
    select: function( event, ui ) {
        var namess = ui.item.data.split("|");                       
        $('#desi'+lastChar).val(namess[1]);
        $('#speci'+lastChar).val(namess[2]);
        $('#univr'+lastChar).val(namess[3]);
        $('#col'+lastChar).val(namess[4]);
        $('#addr'+lastChar).val(namess[5]);
        $('#phone'+lastChar).val(namess[6]);
        $('#email'+lastChar).val(namess[7]);
    }               
});});
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 酬劳2w元求合作写文章
    • ¥15 在现有系统基础上增加功能
    • ¥15 远程桌面文档内容复制粘贴,格式会变化
    • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图