选择“自动完成”框后,更新到文本框中



当我使用zii.widgets.jui.CJuiAutoComplete'小部件时,我遇到了两个问题

P1)当我按照创建阵列时

a[1]=>'aa'
a[2]=>'bb'
a[3]=>'cc'

它不起作用。但是如果阵列像这个

a[0]=>'aa'
a[1]=>'bb'
a[2]=>'cc'

它运行良好。

Q1)我应该如何使用数组来处理小部件,如下所示?

a[1]=>'aa'
a[2]=>'bb'
a[3]=>'cc'

p2)当我通过上面的小部件选择一个值时,我想从DB中获取一些数据,并通过ajax将它们放入其他输入框中。

Q2)我该怎么办?

问题的Fo P1以json格式传递数据并尝试

对于你问题的p2,你可以使用ajax,如所示

$('#yourautoCompleteId').change(function(){
    var selecteddata=$(this).val();
    $.ajax({
        url: "'.$this->createUrl('Controller/yourMethod').'",
        data: {
            //special:specialisation,
            data   :selecteddata,
            },
            type:"GET",//you can also use POST method
            dataType:"html",//you can also specify for the result for json or xml
            success:function(response){
                //write the logic to get the response data as u need and set it to the fields 
                $("#dataId").val("SetHere");
                $('#quantityId').val("setHere");
             },
             error:function(){
                    //TODO: Display in the poll tr ifself on error   
                    alert("Failed request data from ajax page"); 
                }
        });
})

或者,您可以将此线程引用到文本框"自动完成更新演示"中以完成更新任务

最新更新