如何在第一个combobox(g:select)的基础上填充第二个combobox(g:select)值? [英] How to populate 2nd combobox(g:select) values on basis of 1st combobox(g:select)?
问题描述
我试图在第一个组合框( 域类: GSP: 我该如何正确执行此操作? 当页面呈现时,不要在第二个组合框中填充项目,并在第一个组合框中存在值更改时填充它。 在第一个组合框中添加onchange事件(可以使用jquery或纯Javascript),以填充电话数据基于选定人员的人口。在这里,您可以使用ajax调用服务器来执行某个操作,例如: I'm trying to load 2nd combobox ( Domain classes: GSP: How can I do this properly? Don't populate the items in the second combobox when the page is rendered, populate it when there is a value change in the 1st combobox. Add onchange event on the first combobox (you can use jquery or plain Javascript) that will fill telephone data population based on chosen person. Here you can use an ajax call to the server to an action, something like:
这篇关于如何在第一个combobox(g:select)的基础上填充第二个combobox(g:select)值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! g:select $ c)的选择上加载第二个组合框(
g:select
)
class Person {
String name
static hasMany = [电话:电话]
}
class电话{
String tNumber
Person person
static belongsTo = [person:Person]
}
< td>
< td>
< td>
< td>
def getTelephones = {
def telephoneInstanceList = Telephone.findAllByPerson(Person.get(params.personId))
def telephones = telephoneInstanceList.collect {[id:it.id,phone:it.tNumber]}
将电话呈现为JSON
}
g:select
) values on the selection of 1st combobox (g:select
) value in GSP.class Person {
String name
static hasMany = [telephones:Telephone]
}
class Telephone {
String tNumber
Person person
static belongsTo = [person:Person]
}
<td>
<g:select id="person" name="selectedPersonId" from="${Person.list(sort:name, order:asc)}" value="name" optionValue="name" optionKey="id" noSelection="['0':'--Select--']" />
</td>
<td>
<g:select id="telephone" name="selectedTelephoneId" from ="${person.telephones}" value="tNumber" optionValue="tNumber" optionKey="id" noSelection="['0','--Select--']"/>
</td>
<td>
<g:select id="person" name="selectedPersonId" from="${Person.list(sort:name, order:asc)}" value="name" optionValue="name" optionKey="id" noSelection="['0':'--Select--']" />
</td>
<td>
<g:select id="telephone" name="selectedTelephoneId" from ="${[]}" value="tNumber" optionValue="tNumber" optionKey="id" noSelection="['0','--Select--']"/>
</td>
def getTelephones = {
def telephoneInstanceList = Telephone.findAllByPerson(Person.get(params.personId))
def telephones = telephoneInstanceList.collect {[id: it.id, phone: it.tNumber]}
render telephones as JSON
}