0

我正在尝试实现 CJuiAutoComplete 小部件,但无法显示任何结果。这是我的代码:

HighSchoolsController.php

public function actionSearchHighSchools() {

$criteria=new CDbCriteria;
$model = new HighSchools;
$criteria->compare('SchoolName',$model->SchoolName,true);
$criteria->compare('City',$model->City,true);
$criteria->compare('State',$model->State,true);

$dataProvider = new CActiveDataProvider($model, array('criteria'=>$criteria));
$highSchools = $dataProvider->getData();
$return_arr = array();
foreach($highSchools as $highSchool){
  $return_arr[] = array(
    'value' => $highSchool->SchoolName,
    'label' => $highSchool->SchoolName,
    'id' => $highSchool->id,

  );
}
return CJSON::encode($return_arr);

}

_buildEducation.php (view file)

<?php
  $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'name'=>'highschool',
    'sourceUrl'=>$this->createUrl('highSchools/searchHighSchools'),
    'options'=>array(
      'minLength'=>'2',
    )
  ));
?>

现在,在我的控制器函数中,如果我 var 转储CJSON::encode($return_arr)而不是返回它,我会得到以下输出:

string(688) "[{"value":"ALBERT P BREWER HIGH SCH","label":"ALBERT P BREWER HIGH SCH","id":"1"},{"value":"ALBERTVILLE HIGH SCH","label":"ALBERTVILLE HIGH SCH","id":"2"},{"value":"ALICEVILLE HIGH SCH","label":"ALICEVILLE HIGH SCH","id":"3"},{"value":"ALMA BRYANT HIGH SCH","label":"ALMA BRYANT HIGH SCH","id":"4"},{"value":"ANDALUSIA HIGH SCH","label":"ANDALUSIA HIGH SCH","id":"5"},{"value":"ANNISTON HIGH SCH","label":"ANNISTON HIGH SCH","id":"6"},{"value":"ARAB HIGH SCH","label":"ARAB HIGH SCH","id":"7"},{"value":"ASHVILLE HIGH SCH","label":"ASHVILLE HIGH SCH","id":"8"},{"value":"ATHENS HIGH SCH","label":"ATHENS HIGH SCH","id":"9"},{"value":"AUBURN HIGH SCH","label":"AUBURN HIGH SCH","id":"10"}]"

所以我知道小部件正在发送正确的数据,就像我在标题中所说的那样,网络请求返回正常,状态为 200,但由于某种原因,结果不会显示。谁能看到我做错了什么?我从 Yii 文档和论坛中提取了代码并根据我的需要进行了定制,但代码本质上与那些说它适用于他们的人相同

4

1 回答 1

0

想通了...需要回显json结果而不是返回它们

于 2013-09-13T14:26:39.580 回答