jquery ui以zend形式自动完成

时间:2011-11-17 08:38:39

标签: jquery json jquery-ui zendx zend-framework

我的动作控制器中返回了JSON数据:

$results = $repo->getMatchingCityName($searchTerm);

我得到的回应:

[{"CityName":"Montreal"},{"CityName":"New york"}]........

但是jquery ui autocomplete没有显示任何内容

尝试

$this->_helper->json(array_values($results));

Zend_Json::encode($results);

但没用。我如何转换成

[{"value":"Montreal","label":"Montreal"},{"value":"New york","label":"New york"}]

1 个答案:

答案 0 :(得分:0)

试试此代码

$results = $repo->getMatchingCityName($searchTerm); // [{"CityName":"Montreal"},{"CityName":"New york"}]........


$data = Zend_Json::decode($results);

$new = array();

foreach ($data as $row) {
   $temp['value'] = $row['CityName'];
   $temp['label'] = $row['CityName'];
   array_push($new, $temp);
}

$newEncode = Zend_Json::decode($new); //[{"value":"Montreal","label":"Montreal"},{"value":"New york","label":"New york"}]