我試圖在我的項目中實現CJuiAutoComplete,但它不工作。過去幾天我研究了這個問題,並嘗試了一切。看起來發生了什麼(或者在這種情況下沒有發生)是控制器中的查找操作沒有被調用。如果將源設置爲簡單的項目數組,我也無法使其工作。我究竟做錯了什麼?Yii CJuiAutoComplete不工作
_form.php這個
<?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model' => $model,
'attribute' => 'zipcode',
'source' => $this->createUrl('address/lookup'),
'name' => 'zipcode',
'htmlOptions' => array('size'=>'5'),
'options' => array(
'showAnim'=>'fold',
'minLength' => 1,
)) ?>
AddressController.php
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update','lookup'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionLookup()
{
echo "Lookup Action";
}
您是否嘗試過'sourceUrl' insted的'source'?即''sourceUrl'=> array('address/lookup')' – dInGd0nG
是的,我也嘗試了sourceUrl。我很難過! – nimble
@ user1417526可能是您在同一個視圖文件中使用同一模型的'zipcode'屬性定義了一個小部件(一個textField或某物)。在這種情況下,自動完成可能無法工作 – dInGd0nG