【问题标题】:Yii - CJuiAutoComplete no results displaying even though network request has status 200Yii - 即使网络请求的状态为 200,CJuiAutoComplete 也没有显示结果
【发布时间】:2013-09-17 00:30:42
【问题描述】:

我正在尝试实现 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 文档和论坛中提取了代码并根据我的需要进行了定制,但代码本质上与那些说它适用于他们的人相同

【问题讨论】:

    标签: php yii autocomplete widget jquery-autocomplete


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2015-04-22
      • 2020-08-18
      • 2014-04-05
      • 2018-10-23
      • 2019-04-02
      • 2018-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多