gpt4 book ai didi

javascript - 根据grails中的所选选项显示其他详细信息

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

<head>
<g:javascript library='jquery' />
<r:layoutResources />
<script type="text/javascript">
function getGroupsDetails(){
var selectedGroup = jQuery("#group").val();
if(selectedGroup != "")
${remoteFunction (controller: 'groups', action: 'details', params: '\'groupId=\' + selectedGroup', update: 'details')}
}
</script>
</head>
<body>
<div class="col-xs-12 col-sm-4">
<strong>By Group Name :</strong>
<g:select id="groups" name="groupName" from="${Groups.list()}" value="${groupsInstance?.id}" noSelection="['':'-Select-']" optionKey="id" onChange="getGroupsDetails();" />
<div id="details"></div>
</div>
</body>
</html>

详细 Action 如下
def details(){
println "in details"
def groupIns = Groups.get(params.id)
println groupIns.id
render(template: "details", model: [groupIns: groupIns])
}

现在,它进入了javascript以及details Controller 。在 Controller 中,我也打印了ID。但在gsp中什么也没显示...

最佳答案

在类中包含toString。当对象打印我们的tostring返回gname

    class Groups {

String gowner

String gname

int devicenum

static constraints = {

}


String toString() {
"$gname"
}

}

first.gsp:

在select中不需要list.gname(),因为我们包括toString()。在下面,当我们选择group时,它调用javascript函数,该函数将调用更新特定div的 Action 。我正在用ajax进行操作。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<g:javascript library='jquery' />
<r:layoutResources />

<script type="text/javascript">
function getGroupDetails(){
alert("Function calling");
var selectedGroup = jQuery("#group").val();
alert(selectedGroup);
if(selectedGroup != "")
${remoteFunction (controller: 'group', action: 'details', params: '\'groupId=\' + selectedGroup', update: 'details')}
}

</script>
</head>


<g:select id="group" name="groupName" from="${Groups.list()}"
value="${groupInstance?.id}" noSelection="['':'-Select-']" optionKey="id"
onChange="getGroupDetails();" />

<div id="details"></div>

Controller Action :
def details(){
println params.groupId
def groupIns = Group.get(params.groupId)
render(template: "details", model: [groupIns: groupIns])
}

_details.gsp:
 Name:${groupIns.gname}
Owner:${groupIns.gowner}
Devicenum:${groupIns.devicenum}

关于javascript - 根据grails中的所选选项显示其他详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22680634/

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