简体   繁体   English

用于从JSON或类似数据生成/呈现动态HTML表单的JavaScript?

[英]JavaScript to generate/render dynamic HTML form from JSON or similar data?

I would like to offer viewers a contact form that is modified according to the user's input. 我想为观众提供一个根据用户输入修改的联系表格。 An example of such a form is on the Ext JS site . 这种表单的一个例子是在Ext JS站点上 I have not looked into the product, but I would like to know if there are any other programs/functions that generate such a form dynamically? 我没有看过产品,但我想知道是否有其他程序/功能动态生成这样的表格? I found only samples on adding other input elements to existing forms. 我发现只有样本才能在现有表单中添加其他输入元素。

Here are some other implementations: 以下是其他一些实现:

I also plan to add this functionality to my own js-forms library, which would also handle validation. 我还计划将此功能添加到我自己的js-forms库中,该库也将处理验证。

You can always create whatever DOM structure you like using JavaScript. 您始终可以使用JavaScript创建您喜欢的任何DOM结构。 Be it additional inputs or even additional FORM elements. 无论是额外的输入还是其他FORM元素。 It then depends of course what you use on the server side to process form data and how you do that. 然后,它当然取决于您在服务器端使用什么来处理表单数据以及如何执行此操作。

Maybe I haven't understood the nature of your problem because you haven't explained yourself too good. 也许我没有理解你问题的本质,因为你没有解释自己太好。

ExtJS is a JavaScript library that does everything on the client side. ExtJS是一个JavaScript库,可以在客户端执行所有操作。 It also provides the ability to rapidly create user interface by providing Javascript configuration objects that will result in rich widget creation. 它还提供了通过提供Javascript配置对象来快速创建用户界面的能力,这将导致创建丰富的小部件。

You can do lots with jQuery (and jQueryUI) as well, but it's up to you how to do it. 您可以使用jQuery(和jQueryUI)做很多事情,但这取决于您如何做到这一点。 ExtJS just has these very functionally rich and visually consistent set of client controls/widgets that you can use out of the box without much additional development (not to mention bug killing that comes along custom development). ExtJS只是拥有这些功能丰富且视觉上一致的客户端控件/小部件集,您可以在没有太多额外开发的情况下使用它们(更不用说自定义开发中出现的bug)。

For instance: When writing an Asp.net MVC application it's very easy to issue an Ajax call that would return HTML of so called partial view with complete HTML of your form that you can then easily display in a modal dialog for instance. 例如:在编写Asp.net MVC应用程序时,很容易发出一个Ajax调用,该调用将返回所谓的局部视图的HTML,其中包含完整的表单HTML,然后您可以轻松地在模式对话框中显示。

If you do need all that functionality to create a desktop-like application I suggest you do take a plunge into ExtJS because it is definitely a very good product. 如果您确实需要所有这些功能来创建类似桌面的应用程序,我建议您尝试使用ExtJS,因为它绝对是一个非常好的产品。 I've used it about 3 years ago (version 2) on some project and I was amazed by the work they've done with it. 我在大约3年前(版本2)使用它来进行某些项目,我对他们用它完成的工作感到惊讶。 It's very feature rich product that makes it really easy to create desktop like web applications. 它功能丰富的产品使得创建像Web应用程序这样的桌面非常容易。

But if you're after a usual web site then a desktop-like experience is probably not what you should give to your visitors. 但是,如果你是在一个普通的网站之后,那么类似桌面的体验可能不是你应该给你的访问者的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM