我的视图页面上需要两个 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 );
};');
?>