0
目前我的自動完成的作品中顯示用戶的名字,但我想連接的第一個名字,姓氏等如何在下面的代碼實現這一點?連接多個領域CakePHP中使用AJAX的自動完成功能顯示
<script type="text/javascript">
$(function() {
$(".suggest").autocomplete({
source: function(request, response) {
$.ajax({
url: '<?php echo $this->Html->url(array('controller' => 'searches', 'action' => 'suggestUser')); ?>',
dataType: "json",
data: {
//request.term is the value of the current textbox.
term: request.term
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.User.firstName,
value: item.User.firstName
}
}));
}
});
},
minLength : 1
});
});
在我的控制器,以下代碼下面是我的邏輯來搜索字段。
function suggestUser() {
if (isset($_GET["term"])) {
$term = $_GET["term"];
$result = $this->User->find('all', array(
'conditions' => array(
'User.firstName LIKE' => $term . '%'
),
'fields' => array(
'firstName'
)
));
if ($term) {
$this->set('results', $result);
$this->view = 'Json';
$this->set('json', 'results');
}
}
}
,我應該適用這個虛擬領域?哪部分? –