Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

CJuiAutoComplete with ID [SOLVED]

$
0
0
Hi there,

I have a problem when using the CJuiAutoComplete, specifically in relation to the result in JSON, which brings me ID and NAME.

Controller action JSON code:
$arr = array();

if (isset($_GET['term']))
{
	$sql = "SELECT Id, Nome FROM Pessoa WHERE Nome LIKE ':Nome%'";
	$command = Yii::app()->db->createCommand($sql);
	$command->bindValue(":Nome", $_GET['term'], PDO::PARAM_STR);
	$models = $command->queryAll();

	foreach ($models as $model)
	{
		$arr[] = array(
			'id'=>$model['Id'],
			'nome'=>$model['Nome'],
		);
	}
}

echo CJSON::encode($arr);
Yii::app()->end();

Controller result:
[{"id":"1","nome":"Fulano da Silva"},{"id":"2","nome":"Fulano de Souza"}]

View:
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
	'id'=>'comboPessoa',
	'name'=>'comboPessoa',
	'source'=>$this->createUrl('pessoa/JSON'),
	'options'=>array(
		'showAnim'=>'fold',
		'delay'=>800,
	),
));


The problem is that when i put the controller to return the ID, CJuiAutoComplete does not work. To load the return JSON, but the list of peoples was to display below the input is not displayed, but when put to the JSON return only the name, it works normally.

Does anyone have any idea how to work with CJuiAutoComplete returning a JSON structure ID and Name?

Thanks in advance to all who collaborate.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>