2
이것이 이미 존재하지만 사과가 작동하지 않을 경우 사과드립니다. ID를 내 테이블에 저장하고 저장해야합니다. 이 이름은 다른 모델 (테이블)에서 오는 이름입니다. 나는 크롬 네트워크 검사관에서 엘츠를 검사 할 때 이름과 ID를 얻었습니다. 값은 보이지 않습니다 .. 그러나 ID를 사용하여 경고를 표시하려고 할 때 값이 표시됩니다 ..Yii CJuiAutoComplete 값이 표시되지 않습니다.
사람이 PLS
내 _form.php이 같은 나를 통해 UR 도움을 이름을 볼 수 --thanks를 얻을하는 데 도움이 될 수 있습니다 : 이름과 아이디의를 얻기를위한
<div class="row">
<?php echo $form->labelEx($typeModel,'benefit_type'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'attribute'=>'name',
'model'=>$typeModel,
'sourceUrl'=>array('benefit/benefit_type_list'),
'value'=>'Please select',
'name'=>'name',
'id'=>'id',
'options'=>array(
'minLength'=>'0',
'select'=>"js:function(event, ui) {
alert(ui.item.id);
// $('#organisation_id').val(ui.item.id);
}",
),
'htmlOptions'=>array(
'id'=>'id',
'size'=>45,
'maxlength'=>45,
),
)); ?>
<?php echo $form->error($typeModel,'benefit_type'); ?>
확장 클래스 것은 :
<? class EAutoCompleteAction extends CAction
{
public $model;
public $attribute;
public $id;
private $results = array();
public $returnVal = '';
public function run()
{
if(isset($this->model) && isset($this->attribute)) {
$criteria = new CDbCriteria();
$criteria->compare($this->attribute, $_GET['term'], true);
$model = new $this->model;
foreach($model->findAll($criteria) as $m)
{
// $this->results[] = $m->{$this->attribute};
//$this->results[] = $m-<{$this->id};
$this->results[] = array(
'name' => $m->{$this->attribute},
'id'=> $m->id
);
/* $this->returnVal .= $m->getAttribute('name').'|'
.$m->getAttribute('id'). "\n"; */
}
}
echo CJSON::encode($this->results);
}
}
?>
내 컨트롤러 :이 확장을 사용하지만 jQuery의 자동 완성 사용하고 EAutoCompleteAction에서 데이터 세트가 아마 필요가 있기 때문에 그것은 잠시이었다
public function actions()
{
return array(
'benefit_type_list'=>array(
'class'=>'application.extensions.EAutoCompleteAction',
'model'=>'BenefitType', //My model's class name
'attribute'=>'name', //The attribute of the model i will search
),
);
}
답장을 보내 주셔서 감사합니다. 하지만 결과 배열에서 값을 가져 오는 것이 문제는 아닙니다. Cjuiautocomplete의 문제. 뭔가를 여기서 고쳐야 해. – Developer