客户端:
{% block scripts %}
<script>
$("#review").autocomplete({
serviceUrl: '{{ search_reviewer_path() }}',
minChars: 3,
width: '200px',
onSelect: function(value, data){
$("#review").val(data.value);
window.location.href = data.url;
}
});
</script>
{% 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);
}
共同学习,写下你的评论
评论加载中...
作者其他优质文章