gpt4 book ai didi

grails - grails通过远程功能调用ajax后在select中呈现一个列表

转载 作者:行者123 更新时间:2023-12-02 15:28:32 24 4
gpt4 key购买 nike

我正在使用grails 2.1.1。我有一个选择框,在更改时,我通过remothFunction调用一个 Action 来更新另一个选择。该列表正在 Controller 中填充,但未在所需的选择框中呈现。有人可以帮我吗?这是我的代码如下:

我的 View 页面具有两个选择和远程功能>>>

 <html>
<head>
<title>Render District & Thana</title>

<g:javascript plugin="jquery" library="jquery" src="jquery/jquery-1.8.0.js" />

<script>
function loadThana(districtId) {
<g:remoteFunction controller="greeting" action="loadThanaByDistrict" update="thanaId" params="'districtId='+districtId"/>
}
</script>

</head>

<body>
<g:form controller="greeting" action="renderDistrictThana">
Select District : <g:select
name="districtId"
id="districtId"
from="${district}"
optionKey="id"
optionValue="districtName"
noSelection="['null':'Select District']"
onchange="loadThana(this.value)"/><br/>


Select Thana : <g:select
name="thanaId"
id="thanaId"
from="${thana}"
optionKey="id"
optionValue="thanaName"
noSelection="['null':'Select Thana']"/><br/>

<g:submitButton name="submit" id="submit" value="Render Distric & Thana"/>
</g:form>
</body>
</html>

我在第二个组合中呈现列表的操作>>>
def loadThanaByDistrict() {
def district = District.get(params.districtId?.toLong())
def thana = Thana.findAllByDistrict(district)

render thana
}

最佳答案

您的 Controller 可能如下所示,

def loadThanaByDistrict(){
def district = District.get(params.districtId?.toLong())
def thana = Thana.createCriteria().list{eq('district',district)}
String options
thana.each{ options += "<option value='"+[replace it with your expected field]+"'>"+[replace it with your expected field]+"</option>"
render options
}

我希望它能正常工作。

关于grails - grails通过远程功能调用ajax后在select中呈现一个列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24035332/

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