プログラムに動的オートコンプリートを実装しようとしました。最初の入力後、完全に機能しています。ただし、最初の試行に対する提案は表示されません。ただし、サーバーはオートコンプリートに必要なソースに応答しています。これが私のコードです。
$('.autocomplete').live('keyup', function(){
$this = $(this);
var search = $this.val();
$.ajax({
url:'/package/index/search/keyword/'+search+'/format/json',
async: false,
success: function(res){
//console.log(res.options);
//console.log(res.defined_ids);
staticObject = res.defined_ids;
$this.autocomplete({
source: res.options
});
}
});
});
サーバー側のコードは
$keyword = $this->_getParam('keyword');
$elementDetailModel = new Package_Model_ElementDetail();
$arr = $elementDetailModel->searchElementDetail($keyword);
$this->view->options = $arr['options']; // returns in the format array("test2","my new test", "night stay in delux room")
$this->view->defined_ids = $arr['defined_ids']; // returns in the format array(21::21=>"test2", 22::22=>"my new test", 24::24=>"night stay in delux room")
コンソールで defined_ids とオプションを firebug に記録したとき、テキスト フィールドに「t」と入力すると、次の応答が返されました。
オプション:
[「test2」、「私の新しいテスト」、「デラックス ルームでの宿泊」]
定義済み ID:
Object { 21::21="test2", 22::22="新しいテスト", 24::24="デラックス ルームでの宿泊"}
どんな助けもかなりのものです。前もって感謝します。