Answer the question
In order to leave comments, you need to log in
How to display array elements in a list using CJuiAutoComplete in Yii?
Greetings!
Tell me how to display in the drop-down list of the text field the elements of the array that was received by the controller action as a result of the search?
This is what the widget looks like:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'searchbox',
'value'=>'',
'source'=>Yii::app()->createUrl('customer/places/autocomplete'),
'options'=>array(
'showAnim'=>'fold',
'minLength'=>'1',
'select'=>'js:function( event, ui ) {
$("#searchbox").val( ui.item.label );
$("#selectedvalue").val( ui.item.value );
return false;
}',
),
'htmlOptions'=>array(
// 'autocomplete'=>'off',
'onfocus' => 'js: this.value = null; $("#searchbox").val(null); $("#selectedvalue").val(null);',
'class' => 'input-xxlarge search-query',
'placeholder' => "Живой поиск...",
),
));
public function actionAutocomplete($term)
{
$query = Places::model()->findallbyattributes( array('name'=>$term));
$list = array();
foreach($query as $q)
{
$data['value']= $q['id'];
$data['label']= $q['name'];
$list[]= $data;
unset($data);
}
echo json_encode($list);
}
$list[]= $data;
$list[]= $data['name'];
array(array( 'id', 'name' ),array( 'id', 'name' ),array( 'id', 'name' ),array( 'id', 'name' ))
Which is formed in the first version. foreach($model as $item)
{
$data['id']= $item['id'];
$data['value']= $item['name'];
$list[]= $data;
unset($data);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question