gpt4 book ai didi

jquery-ui - grails jQuery自动完成功能为另一个辅助自动完成功能选择的ID

转载 作者:行者123 更新时间:2023-12-02 14:45:08 24 4
gpt4 key购买 nike

我一直在遵循Alidad博客中的指南,以在grails中启用jquery自动完成功能:

http://alidadasb.blogspot.co.uk/2011/12/enabling-jquery-autocomplete-with.html

Country.groovy

package rentspace
class Country {
String name
static hasMany = [cities:City]
}

城市
package rentspace

class City {
//static belongsTo = [country:Country]
static belogsTo = Country
Country country
String name
static constraints = {}
}

GSP页面:
<g:autoComplete id="countrySearch"
action='autocompleteCountry'
controller='any'
domain='rentspace.Country'
searchField='name'
collectField='id'
value=''
/>

<g:textField id="hiddenState" name="hiddenState" value=""/>

<label>City:</label>
<g:autoComplete name="citySearch" id="citySearch"
cid=""
action='autocompleteCityAction'
controller='any'
domain='rentspace.City'
searchField='name'
value=''
/>

AutoCompleteTagLib.groovy
package rentspace

class AutoCompleteTagLib {
..
if (attrs.style) styles = " styles='${attrs.style}'"

if (attrs.cid)
cid="&cid="+attrs.cid
else
cid=""

.......

out << "&order="+attrs.order
out << ""+cid



out << "&collectField="+attrs.collectField

out << "',select: function(event, ui) {"
out << " \$('#hiddenState').val(ui.item.id);},"
//out << " \$('#citySearch').attr('cid',ui.item.id);},"
out <<" search: function() {"
out << "\$('#hiddenState').val('');"
//out << "\$('#citySearch').attr('cid','');"
out <<"}"

out << ", dataType: 'json'"
out << "});"
out << " });"
out << "</script>"

}

def autoCompleteHeader = {
out << "<style>"
out << ".ui-autocomplete-loading"
out << " { background: white url(${resource(dir:'images',file:'ajax-loader.gif')}) right center no-repeat }"
out << " </style>"
}
}

我的问题与jquery返回的双值有关,如果我将值返回到隐藏或文本字段框中,它似乎确实起作用。我想做的是将国家ID返回到第二个自动完成框,即citySearch。
因此,一旦用户自动完成国家/地区设置,则国家ID会以cid ='1'的形式返回,或者是对citySearch自动完成框的cid属性返回的ID。

在标签库lib中,有一段注释掉了,该段成功返回或更新了hiddenState字段的值,但是无论我试图失败以何种方式更新cid值呢?
        //out << "  \$('#citySearch').attr('cid',ui.item.id);},"

有人成功做过这样的事吗?

E2A:

https://github.com/vahidhedayati/grailscountrycity

可以从上面的链接下载项目,自述文件中有关于此问题的更多信息

最佳答案

此问题已由Alidad解决: {countryid:\ $('#hiddenField')。val()}

https://github.com/alidadasb/CountryCityAutoComplete

out << "\$('#" + attrs.id+"').autocomplete({ "
out << " source: "
out << " function(request, response) { "
out << " \$.getJSON(' "
out << createLink(link)
out << "?"
out << "term=' + request.term + '"
out << "&domain="+ attrs.domain
out << "&searchField="+attrs.searchField
out << "&max="+attrs.max
out << "&order="+attrs.order
out << "&collectField="+attrs.collectField
out << "', { countryid: \$('#hiddenField').val() }, "
out << " response); } "
out << ", dataType: 'json'"
out << "});});"
out << "</script>"

工作版本可以在这里看到:
http://countrycity.cloudfoundry.com

关于jquery-ui - grails jQuery自动完成功能为另一个辅助自动完成功能选择的ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13936216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com