在Yii中多CJuiAutocomplete - 项目未呈现 [英] Multiple CJuiAutocomplete in Yii - items not rendering

查看:144
本文介绍了在Yii中多CJuiAutocomplete - 项目未呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要查看页面上的两个CJuiAutocomplete项目。遗憾的是 - 其中只有一个是正确呈现项。另一种 - 呈现空行。我在Firebug检查和值是从数据库中正确检索。其实如果我改变的顺序 registerScript - 只有从去年自动完成 registerScript 渲染项正确

下面是我的code:

 < PHP
    $这个 - >小部件('zii.widgets.jui.CJuiAutoComplete',阵列(
        '名'=> autocities',
        sourceUrl'=> $这个 - > createUrl('项目/ dynamicGetCities'),
        '选项'=>阵列(
            '的minLength'=> 2,
            '选择'=> JS:函数(事件,UI){
                        $('#lastSelectedCityId)VAL(ui.item.idCity)。
                        变种ciname = ui.item.name +(+ ui.item.directional +)';
                        $('。selectedCity)HTML(ciname)。
                    }
                
        )
    ));
?>
< BR />< BR />
< PHP
    $这个 - >小部件('zii.widgets.jui.CJuiAutoComplete',阵列(
        '名'=> autostreets',
        sourceUrl'=>
            JS:功能(请求,响应){
                $阿贾克斯({
                    网址:'(项目/ dynamicGetStreets')$这个 - &GT createUrl。'',
                    数据类型:JSON
                    数据:{
                        长期:request.term,
                        idCity:$(#lastSelectedCityId)VAL()
                    },
                    成功:功能(数据){
                        响应(数据);
                    }
        })}',
        '选项'=>阵列(
            '的minLength'=> 2,
            '选择'=> JS:
                功能(事件,UI)
                {
                    $('#lastSelectedStreetId)VAL(ui.item.idStreet)。
                    $('。selectedStreet)HTML(ui.item.name)。
                }
        )
    ));    Yii的应用::() - GT; clientScript-> registerScript('输入','
        $(#autostreets)。数据(自动完成)._ renderItem =功能(UL,项目){
        返回$(<立GT;< /李>中)
        。数据(item.autocomplete项)
        .append(< A>中+ item.name +< BR /><跨度风格= \\FONT-SIZE:9px; \\>Abonentów:+ item.customCount +< / SPAN> &所述; / A>中)
        .appendTo(微升);
    };');    Yii的应用::() - GT; clientScript-> registerScript('输入','
        $(#autocities)。数据(自动完成)._ renderItem =功能(UL,项目){
        返回$(<立GT;< /李>中)
        。数据(item.autocomplete项)
        .append(< A>中+ item.name + - + item.directional +< BR /><跨度风格= \\FONT-SIZE:9px; \\>Abonentów:+项目.customCount +&下; /跨度>&下; / A>中)
        .appendTo(微升);
    };');
?>


解决方案

这么多的搜索和询问这里SO之后,我发现它嘿嘿。
答案是在方法 registerScript 简单 - 第一个参数是脚本的唯一的ID。该ID是一样的两次因此它被覆盖previous之一。谢谢你。

I need two CJuiAutocomplete items on my view page. Unfortunately - only one of them is rendering items properly. The other one - renders empty rows. I checked in firebug and the values are retrieved from database properly. Actually if I change the order of the registerScript - only the autocomplete from last registerScript renders items properly.

Here is my code:

<?php
    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'name' => 'autocities',
        'sourceUrl'=>$this->createUrl('projects/dynamicGetCities'),
        'options' => array(
            'minLength' => 2,
            'select' => "js: function(event, ui) {
                        $('#lastSelectedCityId').val(ui.item.idCity);
                        var ciname = ui.item.name + ' (' + ui.item.directional + ')';
                        $('.selectedCity').html(ciname);
                    }
                "
        ),
    ));
?>
<br/><br/>
<?php
    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
        'name' => 'autostreets',
        'sourceUrl' => 
            'js: function(request, response) {
                $.ajax({
                    url: "'.$this->createUrl('projects/dynamicGetStreets').'",
                    dataType: "json",
                    data: {
                        term: request.term,
                        idCity: $("#lastSelectedCityId").val()
                    },
                    success: function (data) {
                        response(data);
                    } 
        })}',
        'options' => array(
            'minLength' => 2,
            'select' => "js: 
                function(event, ui) 
                {
                    $('#lastSelectedStreetId').val(ui.item.idStreet);
                    $('.selectedStreet').html(ui.item.name);
                }"
        ),
    ));

    Yii::app()->clientScript->registerScript('input', '
        $("#autostreets").data("autocomplete")._renderItem = function( ul, item ) {
        return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>"+item.name+"<br/><span style=\"font-size: 9px;\">Abonentów: "+item.customCount+"</span></a>")
        .appendTo( ul );
    };');

    Yii::app()->clientScript->registerScript('input', '
        $("#autocities").data("autocomplete")._renderItem = function( ul, item ) {
        return $( "<li></li>" )
        .data( "item.autocomplete", item )
        .append( "<a>"+item.name + " - " + item.directional+"<br/><span style=\"font-size: 9px;\">Abonentów: "+item.customCount+"</span></a>")
        .appendTo( ul );
    };');
?>

解决方案

So much searching and right after asking here on SO I found it heh. The answer is simple in the method registerScript - first parameter is the unique id of the script. The id was the same both times so it was overriding the previous one. Thanks.

这篇关于在Yii中多CJuiAutocomplete - 项目未呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆