嘗試在自動完成顯示在軌道上
顯示由「術語」過濾列表,使用自動完成在Ruby變種我有一個使用jQuery UI的自動完成功能的軌道3應用程序。我已經達到了可以搜索用戶列表的地步。但是,當我鍵入指定用戶的前幾個字母時,出現整個列表(不知道這是否是我的Javascript或控制器內的project_list的問題),只有一個用戶應該出現。但我不希望它這樣做。從我的理解,我必須採取無功條件,並過濾我的清單,但我不知道該怎麼做,下面的代碼。
用戶controller.rb
def project_list
list=User.all.map{|i|i.full_name}
arr= [].concat(list.sort{|a,b| a[0]<=>b[0]}).to_json
render :json =>arr
end
的application.js
$("#tags").autocomplete({
minLength: 2,
source: function(request, response) {
$.ajax({
url: "/managerlist",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
var results = [];
$.each(data, function(i, item) {
var itemToAdd = {
value: item,
label: item
};
results.push(itemToAdd);
});
return response(results);
}
});
}
});
}
如何傳遞一個參數並完成所有這些?我在這方面沒有任何經驗 – ahmet
我建議你看看這個在rails3應用程序中非常棒的gem。 [https://github.com/crowdint/rails3-jquery-autocomplete](https://github.com/crowdint/rails3-jquery-autocomplete) –