春天 + JQuery 动态绑定
我是 Spring 新手,仍在学习。我想做一些更高级的表单处理。
目前我的问题是动态列表绑定。
我想要一个文本框、一个列表和添加按钮。什么是情景? 用户填充文本框(带有自动完成功能)并点击添加按钮。启动添加操作后,列表将被填充,而不向服务器发出请求。 用户向列表中添加更多项目,然后将表单提交到服务器。
什么是问题?
我不知道如何绑定列表或将动态数据传递到服务器。
目前,我已成功从控制器获取 JSON 响应以及自动完成列表。
Spring 表单适合这项任务吗?实施这个的正确方法是什么?
I am new to Spring and still learning. I want to make some more advanced form handling.
Currently my problem is dynamic list binding.
I want to have one text box, one list and add button. What is scenario?
User populates text box(with autocomplete) and cliks add button. After initiation add action, list gets populated without issuing request to server.
User adds few more items to list, and then submits form to server.
What is problem?
I dont know how to bind list or pass dynamic data to server.
Currently I have managed to get JSON response from Controller with list for autocomplete.
Is Spring forms suitable for this task? What is the right way to implement this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我认为您想要实现的目标的一个尝试。首先:我假设问题不是自动完成/添加到列表,而是如何处理 MVC 端的列表。假设您的命令对象有一个属性“员工姓名”,定义为
在 JSP 端,您可以像这样定义表单列表项:
使用 jQuery 使其“动态”的真正技巧是使用 下一个递增索引。因此,您可以在某个地方:
将它们放在一起,将控制器 formBackingObject 中的列表设置为 AutoPopulatedList
这应该足以让您开始。
Here's a stab at what I think you're trying to achieve. First: I'm assuming the issue isn't autocomplete/add to list, but rather what to do with the list in the MVC side. Let's say your command object has a property "employee names," defined as
On the JSP side, you define the form list items like so:
The real trick to making it "dynamic" with jQuery is to add to the form with the next increasing index. So somewhere you have:
Putting it all together, you set the list in the controller formBackingObject to an AutoPopulatingList
That should be enough to get you started.