プロジェクトにスマート オートコンプリートを追加したいと考えています。ユーザーが任意の入力に単語を入力すると、自分の辞書からオートコンプリートされます。
彼の所有者辞書は、サーバーに送信したすべての単語を (array_values($_POST)) のように保存することによって構築されます。
私の現在のJS
$('input.complete').live('keyup.autocomplete', function(){
var hi=$(this).val().toUpperCase();
var was=this;
$(this).autocomplete({
//PROBLEM Should i consider to change source from ajax/mysql to different source ?
//since there gona be too many requests ??
source: function(request, response) {
$.ajax({ url: '<?=base_url()?>ajax/ac',
//PROBLEM how can i set term=word currently being edited..(start=' ',end=pointerpos)
data: { 'term': this.term },
dataType: "json",
type: "POST",
success: function(data){
if(data.length){
//response(data);
//Commented out cause i dont wana display dropdown.. just typeahead.
if(data[0]['value'].substr(0,hi.length).toUpperCase()==hi){
$(was).val(data[0]['value']);
//currently working with single word inputs..once i get how to select only current word will edit these..
was.selectionStart=hi.length;
was.selectionEnd=data[0]['value'].length;
}
}
}
});
},
select: function(event, ui){},
minLength: 2,
delay: 500
});
ご覧のとおり、2つの問題があります
質問
- ユーザーが入力している現在の単語を選択するにはどうすればよいですか?
- これは私の目標を達成するための良いアプローチですか、それとも別のプラグインを検討する必要があります