douwen1549 2015-03-31 04:08 采纳率: 100%
浏览 18

两个CJuiAutoComplete工作正常,分开。 但不是当放在一起

So it worked totally fine if I only used one CJuiAutoComplete. But it doesn't since I added another one(from different tables). The original view was as follows:

<?php
                $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                    'name' => 'myIdPeg',
                    //'value' => $model->id_peg,
                    'sourceUrl' => $this->createUrl('search'),
                    // additional javascript options for the autocomplete plugin
                    'options' => array(
                        'minLength' => '1',
                        'showAnim' => 'fold',
                        'focus' => 'js:function( event, ui ) {
                            $( "#myIdPeg" ).val( ui.item.id_peg );
                            return false;
                        }',
                        'select' => 'js:function(event, ui) { 
                            $("#myIdPeg").val(ui.item.id_peg);
                            $("#myNamaPeg").val(ui.item.nama_peg);
                            $("#myJabatanPeg").val(ui.item.jabatan_peg); 
                            return false;
                        }',
                    ),
                    'htmlOptions' => array(
                        'style' => 'width: 98%',
                        'placeholder' => 'NIP Baru'
                    ),
                ));
                Yii::app()->clientScript->registerScript('input', '
                    $("#myIdPeg").data("autocomplete")._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append( "<a>"+item.id_peg + " - " + item.nama_peg+"</a>")
                    .appendTo( ul );
                    };');
                ?>

The Controller:

public function actionSearch() {
    $res = array();
    if (isset($_GET['term'])) {
        $qtxt = "SELECT 
                DISTINCT 
                bc.id_peg as id_peg, 
                bc.nama_peg as nama_peg, 
                bc.jabatan_peg as jabatan_peg, 
                CONCAT (bc.id_peg, ' - ', bc.nama_peg) as id_nama_peg 
                FROM pegawai bc
                WHERE bc.id_peg LIKE :qterm 
                ORDER BY bc.id_peg, bc.nama_peg ASC";
        $command = Yii::app()->db->createCommand($qtxt);
        $command->bindValue(":qterm", '%' . $_GET['term'] . '%', PDO::PARAM_STR);
        //$res = $command->queryColumn();
        $res = $command->queryAll();
    }

    echo CJSON::encode($res);
    Yii::app()->end();
}

But, when I added this to the view:

<?php
                $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                    'name' => 'mySubKegiatan',                       
                    'sourceUrl' => $this->createUrl('searchkeg'),                        
                    'options' => array(
                        'minLength' => '1',
                        'showAnim' => 'fold',
                        'focus' => 'js:function( event, ui ) {
                            $( "#mySubKegiatan" ).val( ui.item.sub_kegiatan );
                            return false;
                        }',
                        'select' => 'js:function(event, ui) { 
                            $("#mySubKegiatan").val(ui.item.sub_kegiatan);
                            $("#myBidang").val(ui.item.bidang);
                            $("#mySeksi").val(ui.item.seksi); 
                            $("#myKegiatan").val(ui.item.kegiatan); 
                            return false;
                        }',
                    ),
                    'htmlOptions' => array(
                        'style' => 'width: 98%',
                        'placeholder' => 'Nama Sub Kegiatan'
                    ),
                ));
                Yii::app()->clientScript->registerScript('input', '
                    $("#mySubKegiatan").data("autocomplete")._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append( "<a>"+item.sub_kegiatan + " - " + item.kegiatan+"</a>")
                    .appendTo( ul );
                    };');
                ?> 

And this to the Controller:

public function actionSearchkeg() {
    $res = array();
    if (isset($_GET['term'])) {
        $qtxt = "SELECT 
                DISTINCT 
                bc.kode_master as kode_master,
                bc.kegiatan as kegiatan, 
                bc.sub_kegiatan as sub_kegiatan, 
                bc.bidang as bidang, 
                bc.seksi as seksi,
                CONCAT (bc.sub_kegiatan, ' - ', bc.kegiatan) as sub_nama_keg 
                FROM kegiatan bc
                WHERE bc.sub_kegiatan LIKE :qterm 
                ORDER BY bc.kegiatan, bc.kode_master ASC";
        $command = Yii::app()->db->createCommand($qtxt);
        $command->bindValue(":qterm", '%' . $_GET['term'] . '%', PDO::PARAM_STR);
        //$res = $command->queryColumn();
        $res = $command->queryAll();
    }

    echo CJSON::encode($res);
    Yii::app()->end();
}

Neither of them works. I tried to track the problem by deleting the first CJuiAutoComplete. Turned out the second one that I added later worked.

So the problem is that they work fine, separately. But they don't when put together. Why is that? What have I missed? Thank you. I'm pretty sure I have set different unique parameters as it said here. Really hoping for some help here. Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路