0
我在我的表單中爲我的grails應用程序中的大部分字段中實現了自動完成。來自DB的JQuery自動完成
目前我有這樣的代碼(如下圖),讓我給他們鍵入將建議用戶手動輸入值,在這個例子中,我充滿兩種自動完成兩個字段的值:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$("#parameterName").autocomplete({
source: ["HelloHi", "Moose"]
});
$("#defaultValue").autocomplete({
source: ["Blah", "Bleh"]
});
});
我的問題是,我需要改變什麼,以便我不必手動輸入值,我可以簡單地獲取它從數據庫的列中檢索所有值,並使用它們自動提示/完成?
任何幫助,將不勝感激。
UPDATE:
我在form.gsp功能:
<script>
$(function() {
$("#parameterName").autocomplete({
source: '${g.createLink(controller: 'templateInput', action: 'suggestedParameterNames')}'
});
});
</script>
我有我的控制器templateInput功能:
def suggestedParameterNames() {
def suggestions = templatingService.getSuggestedParamNameValues()
render suggestions as JSON
}
我已經在我的功能服務:
def getSuggestedParamNameValues(){
def sql = new Sql(dataSource)
def row = sql.rows("select distinct parameter_name from template_input")
return row
}
現在我遇到的問題是,當我輸入字段時,它會返回列中的每個值。我想要它,所以如果我輸入單詞'card',它只會提示以'card'開頭的值。
任何想法?
我認爲這個問題是關於jQuery UI自動填充小部件http://jqueryui.com/autocomplete而不是自動完成插件。 – MattZ 2014-10-28 14:42:32
我已更新原始帖子,請檢查。 – Jamie 2014-10-28 15:31:50