Grails:根据另一个组合框加载数据
假设我有一个包含选项 GENERAL、AIR、GROUND 和 SEA 的组合框
<g:select name="group" from="${['GENERAL', 'AIR', 'GROUND', 'SEA']}" valueMessagePrefix="default.category" value="${tipoN}" />
,然后另一个组合框根据您是否选择 GENERAL、AIR、GROUND 或 SEA 来加载某些信息。
假设 GROUND
有 3 个选项,FedEx、USPS、DHL
,但 AIR
有完全不同的选项,AIRPLANE、JET、HOT AIR气球。
另一个
的名称应该是 "commodity"
我想过创建一个 javascript 文件并将所有内容都视为 HTML,但我做了一些谷歌研究,并且是并不像我想象的那么简单。
有谁知道最好的方法是什么?提前致谢!
FG
Let's say I have a combobox with the options GENERAL, AIR, GROUND, and SEA
<g:select name="group" from="${['GENERAL', 'AIR', 'GROUND', 'SEA']}" valueMessagePrefix="default.category" value="${tipoN}" />
And then another combobox that loads certain information depending whether you select GENERAL, AIR, GROUND, or SEA.
Let's say GROUND
has 3 options, FedEx, USPS, DHL
, but AIR
has complete different ones, AIRPLANE, JET, HOT AIR BALLOON
.
The name of the other <g:select>
should be "commodity"
I thought about creating a javascript file and treating everything like HTML but I did some google research and is not as simple as I thought.
Does anyone know what would be the best way to do this?? Thanks in advance!
FG
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您会想为此使用 AJAX。您可以做到这一点的一种方法是使用模板和域对象的组合:
模板:
在您的 gsp 中,上面有选择框:
我确信我弄乱了一些语法,您肯定会必须稍微重构一下才能与您的代码一起使用。但至少你已经有了大概的想法。
要使用它们,请将它们作为
ShippingOption
添加到数据库中。这是一种方法。PS:您还可以动态呈现运输方式。
另请参阅:remoteFunction、g:select, 模板 和 AJAX
Sounds like you'll want to use AJAX for this. One way you could do it is by using a combination of templates, and domain objects:
And the template:
And in your gsp with the select box on it:
I'm sure I've messed up some syntax, and you'll definitely have to refactor this a bit to work with your code. But at least you've got the general idea.
And to use them, add them to the database as
ShippingOption
s. Here's one way to do it.PS: You'd also be able to render the shipping methods dynamically, as well.
See also: remoteFunction, g:select, templates, and AJAX
我会考虑重新设计你的用户界面并改变流程。
您所描述的下拉依赖项表明表单可能应该被分割,并且采用“类似向导”的解决方案将产生一个更加用户友好和可靠的解决方案,该解决方案也可以在没有 JavaScript 的情况下工作。
I would consider re-designing your UI and changing the flow.
A drop-down dependency that you are describing suggests the form should probably be split and adopting a 'wizard-like' solution will result in a more user-friendly and solid solution that will work also without JavaScript.
我在这里有一个使用 AngularJS 和 Grail 的工作示例:
http://wordpress.transentia.com.au/wordpress/2013/12/24/keeping-up-with-the-joneses/
(如果这不合适,那么“风格”很抱歉,但是我认为发布数百行代码和废话也不合适)。
I have a worked example using AngularJS and Grail here:
http://wordpress.transentia.com.au/wordpress/2013/12/24/keeping-up-with-the-joneses/
(apologies if this is not appropriate SO 'style', but I dont' think that posting 100s of lines of code and verbiage is appropriate, either).