Grails gsp 嵌套两个选择
我需要将以下对象
companies = [
{ id: 1, code: "cod1", employessList : [{id:1, name:"name1"}, {id:2, name:"name2"}, ...]},
{ id: 2, code: "cod2", employessList : [{id:4, name:"name1"}, {id:5, name:"name2"}, ...]},
{ id: 3, code: "cod3", employessList : [{id:11, name:"name1"}, {id:12, name:"name2"}, ...]},
...
]
放入 gsp 中,两个
一个用于选择公司,另一个用于选择嵌套的员工。当我更换公司时,员工名单也会更新。
例如,
<div>
<g:select id="companiesSelect" name="companies" from="${companies}"
class="form-control" optionKey="id"
optionValue="code" />
<div>
<div>
<!-- Div with nested elements -->
</div>
有人可以帮我解决这个问题吗?
i've the following object
companies = [
{ id: 1, code: "cod1", employessList : [{id:1, name:"name1"}, {id:2, name:"name2"}, ...]},
{ id: 2, code: "cod2", employessList : [{id:4, name:"name1"}, {id:5, name:"name2"}, ...]},
{ id: 3, code: "cod3", employessList : [{id:11, name:"name1"}, {id:12, name:"name2"}, ...]},
...
]
i need put in gsp, two <g:select>
one to choose the companies and an another to select the employess nested. And when i change the company the employees list update.
for instance,
<div>
<g:select id="companiesSelect" name="companies" from="${companies}"
class="form-control" optionKey="id"
optionValue="code" />
<div>
<div>
<!-- Div with nested elements -->
</div>
Could someone help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有 4 个选项:
控制器操作:
GSP:
其中
refreshPage( this.value )
是一个 JS 函数,用于将公司 ID 发送到控制器操作。将公司+员工的完整列表作为 JSON 加载到页面中,将该数据呈现为选择,并使用 onChange-JS 侦听器刷新第二个选择。
使用Ajax调用将基于公司ID的数据加载到员工选择中。
选项2和3需要大量JS,这里就不贴了。
You have 4 options here:
Controller action:
GSP:
where
refreshPage( this.value )
is a JS-function to send the company id to controller action.Load the full list of companies+employees into the page as JSON, render that data as selects, and use the onChange-JS listener to refresh the 2nd select.
Use Ajax call to load the data based on company id into employees select.
The options 2 and 3 require a lot of JS, so I won't post it here.