哪个表单构建器处理数据和动态输入的多对多关系?
我正在尝试 Dancer 一段时间,并寻找合适的块来构建我的应用程序。框架往往具有平面示例应用程序,一次处理一张表。所以我不知道应该使用哪些工具来构建稍微复杂一点的 CRUD 表单。
假设我创建了一个 Booklovers 应用程序。它应该有一个表单来添加/编辑与作者的书籍。为了解决这个问题,我的数据库中需要 3 个表:books
、authors
和 books_to_authors
。构建一个表单来添加作者的书籍的最佳方法是什么?
注意:
- 不知道一本书可能有多少位作者,我们需要动态添加行。
authors
表可能有数万条记录,因此select
表单元素不适合。- 我们的数据库中可能缺少作者,我们也需要动态添加它们。
所有这些动态部分都需要一些 AJAX。有没有一个好的解决方案将其与 Perl 中的表单创建工具集成?我查看了 CGI::FormBuilder 并且仍在寻找,但我没有找到可以构建的东西如上所述的 3 个连接表的表单。动态客户端部分也仍然需要涵盖。
对于这样一个非常简单的案例,是否有一些最佳实践?
I'm experimenting with Dancer some time, and looking for the right blocks to build my application. Frameworks tend to have flat example applications, dealing with one table at time. So I have no good idea which tools should be used to build a little bit more complex CRUD forms.
Let's say I create a Booklovers app. It should have a form to add/edit books with authors. To cover this I need 3 tables in our database: books
, authors
and books_to_authors
. Which is best way to build a form to add a book with authors?
Note:
- It is not known how many authors a book may have, we need dynamic adding of rows.
- The
authors
table may have tens of thousands of records, so aselect
form element is not suitable. - An author may be missing from our database, we need to add them dynamically, too.
All these dynamic parts needs some AJAX. Is there a good solution to integrate it with form creating tools in Perl? I looked at CGI::FormBuilder and am still looking, but I did not find something that could build forms for 3 joined tables as described. The dynamic client-side part also still needs to be covered.
Are there some best practices for such a pretty simple case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AJAX用于在Web浏览器中渲染数据,它不影响后端数据存储。
books
和authors
表有一个 多对多关系,使用 DBIx-Class 等 ORM 会有所帮助。在 Web 表单中,有一本新的
书
和一组作者
。在服务器端,创建一个book
,然后将authors
添加到book
。浏览 DBIx::Class 食谱以获得一些想法。
很抱歉没有提供简单的答案来解决您的问题。
AJAX is for rendering data in a Web browser, it doesn't affect the back-end data storage.
The
books
andauthors
tables have a many-to-many relationship, using ORMs such as DBIx-Class can help.In the Web form, there is a new
book
and a collection ofauthors
. At the server side, create abook
, then addauthors
tobook
.Browse the DBIx::Class cookbook to get some ideas.
Sorry for not providing a simple answer to solve your problem.
似乎这是一个过于复杂的问题,无法直接解决。
我坚持使用模板表单并使用不同的 jQuery 插件生成动态部分。
我认为这不是最好的方法,但目前还没有看到更好的方法。
Seems it is somehow too complex question to have straightforward solution.
I stick using templates forms and generete dynamic part with different jQuery plugins.
I don't think it is best way, but have not seen better for now.