【问题标题】:Multiple CJuiAutocomplete in Yii - items not renderingYii 中的多个 CJuiAutocomplete - 项目未呈现
【发布时间】:2013-03-12 03:46:34
【问题描述】:

我的视图页面上需要两个 CJuiAutocomplete 项目。不幸的是 - 其中只有一个可以正确渲染项目。另一个 - 呈现空行。我签入了萤火虫,并且正确地从数据库中检索了值。实际上,如果我更改 registerScript 的顺序 - 只有最后一个 registerScript 的自动完成才能正确呈现项目。

这是我的代码:

<?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 );
    };');
?>

【问题讨论】:

    标签: php jquery autocomplete yii itemrenderer


    【解决方案1】:

    这么多搜索,在我在这里询问之后,我找到了它,嘿。 答案在registerScript 方法中很简单——第一个参数是脚本的唯一 ID。 id 两次都是相同的,所以它覆盖了前一个。谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多