ビュー ページに 2 つの CJuiAutocomplete アイテムが必要です。残念ながら、アイテムを適切にレンダリングしているのはそのうちの 1 つだけです。もう 1 つ - 空の行をレンダリングします。firebug をチェックインしたところ、値がデータベースから適切に取得されました。実際にの順序を変更すると、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 );
};');
?>