我的动作控制器中返回了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"}]
答案 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"}]