客户端:

{% block scripts %}

{% endblock %}

服务器端:


/**
* For the autocomplete function on the blacklist page
*/
public function searchAction()
{
$query = trim($this->getRequest()->get('term'));
$blacklists = BlacklistRepository::query($query, Blacklist::$SECTIONS);

$results = array();
foreach ($blacklists as $key => $blacklist) {
$results[] = array(
'label' => $blacklist->getName(),
'url' => $this->generateUrl(
'edit_blacklist',
array('id' => $blacklist->getId())
),
'value' => $blacklist->getName()
);
}

return $this->renderJSONResponse($results);
}