Grails:如何使 ag:textfield 加载一些数据并将其显示在其他 g:textfield 中?
我有两个 g:textfields 在第一个中,我应该写一个数字,比如说 12,在它旁边的 g:textfield 中,它应该加载数字 12 的预定名称。
第一个被命名为“shipper”,另一个被命名为“shipperName” 每当我在“shipper”文本字段中写入代码 12 时,它都应该在“shipperName”框中返回托运人的名称。
提前致谢!
示例:
如果我写数字 12,它应该返回 USPS
http://i53.tinypic.com/2i90mc.jpg< /a>
每个号码都应该有不同的“shipperName”
再次感谢!
I have two g:textfields
in the first one I should write a number lets say 12 and in the g:textfield next to it it should load the predetermined name for number 12.
The first one is named 'shipper' and the other 'shipperName'
Whenever I write the code 12 in the 'shipper' txtfield, it should return the name of the shipper in the 'shipperName' box.
Thanks in advance!
Examples:
If I write the number 12 it should return USPS
http://i53.tinypic.com/2i90mc.jpg
And every number should have a different 'shipperName'
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 jQuery,这非常简单。检查事件处理程序(“模糊”是您想要的事件处理程序,当用户离开数字框时发生)。
例如:
最后的$(this).val()就是用户刚刚留下的输入字段的值。
“ShipperController.resolveShipper”操作看起来像这样:
您可能还想做其他事情,例如在用户键入时自动填写 ShipperName 字段,而无需离开编辑字段(可能会在延迟后)。然而,事件处理程序保持不变,只是事件发生变化(从“模糊”到“更改”或类似的内容)
That's quite easy if you'll use jQuery. Check out the event handlers ("blur" is the one you want which occurs when the user leaves the numerical box).
For example:
The $(this).val() at the end is the value of the input field the user just left.
And the "ShipperController.resolveShipper" action would look something like this:
There are other things you might want to do, like automatically filling in the shipperName field as the user types without leaving the edit field, probably after a delay. However the event handler stays the same, just the event is changing (from "blur" to "change" or something like this)
要关联两个字符串,最简单的方法是使用对象来创建字典/映射,如下所示;
您可以在此处查看此操作:http://www.jsfiddle.net/dCy6f/
如果您希望第二个值仅在用户完成第一个输入字段的输入后更新,请将“keyup”更改为“change”。
To relate two strings, it's easiest to use an object to create a dictionary/ map, as shown below;
You can see this in action here: http://www.jsfiddle.net/dCy6f/
If you want the second value only to update when the user has finished typing into the first input field, change "keyup" to "change".