jqueryjsonjquery-uizendxzend-framework

jquery ui autocomplete in zend form


I have JSON data returned in my action controller:

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

Response that i'm getting:

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

But jquery ui autocomplete doesn't show anything

tried

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

and

Zend_Json::encode($results);

But no use. How do I convert into

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

Solution

  • I got it working like this

    $temp = array();
    foreach($results as $row)
    {
        $value = $row["CityName"];
        array_push($temp, array(
            "label" => $value,
            "value" => $value
        ));
    }
    
    $data = $this->_helper->json($temp);
    $this->_helper->autoComplete($data);
    

    Added the view helper in bootstrap

    Zend_Controller_Action_HelperBroker::addHelper(
        new ZendX_JQuery_Controller_Action_Helper_AutoComplete()
    );