Javascript 表单生成器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8923904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript form generator
提问by Matt Brailsford
Does anybody know of a javascript library for auto generating a form based upon a model?
有人知道基于模型自动生成表单的 javascript 库吗?
ie, given a model something like:
即,给定一个模型,例如:
{
name: "someone",
email: "[email protected]",
}
you'd get a form like:
你会得到一个像这样的表格:
Name: ___________
Email: __________
Matt
马特
采纳答案by Rory McCrossan
Try jQuery dForm
试试 jQuery dForm
Example:
例子:
var formdata = {
"action" : "index.html",
"method" : "get",
"elements" :
[
{
"type" : "p",
"html" : "You must login"
},
{
"name" : "username",
"id" : "txt-username",
"caption" : "Username",
"type" : "text",
"placeholder" : "E.g. [email protected]"
},
{
"name" : "password",
"caption" : "Password",
"type" : "password"
},
{
"type" : "submit",
"value" : "Login"
}
]
};
$("#myform").buildForm(formdata);
Builds:
构建:
回答by Michael Uzquiano
If you're looking to generate dynamic forms using jQuery, then I'd recommend taking a look at Alpaca.
如果您希望使用 jQuery 生成动态表单,那么我建议您查看Alpaca。
Alpaca is an open-source forms library (licensed under Apache 2). It generates forms based on JSON Schema using JavaScript and is pretty flexible so that you can register new control types, layouts, constraints and validation functions.
Alpaca 是一个开源表单库(在 Apache 2 下获得许可)。它使用 JavaScript 生成基于 JSON Schema 的表单,并且非常灵活,因此您可以注册新的控件类型、布局、约束和验证功能。
I think it would handle the scenario you described quite easily.
我认为它可以很容易地处理你描述的场景。
It has some nice template features (jQuery Templates), rendering engines for jQuery Mobile and a "connector" pattern so that you can read and persist form and layout definitions from a remote data source.
它有一些不错的模板特性(jQuery 模板)、用于 jQuery Mobile 的渲染引擎和“连接器”模式,以便您可以从远程数据源读取和保存表单和布局定义。
Note: I'm one of the developers at the company behind Alpaca. We open-sourced it because we thought it'd be great for the community. Alpaca is actively developed and we use it for our product (Cloud CMS). Others have used it for other CMS systems as well as projects backed by MongoDB and CouchDB, etc. Thus, it's had a lot of grind put into it.
注意:我是 Alpaca 背后公司的开发人员之一。我们将其开源是因为我们认为它对社区非常有用。Alpaca 正在积极开发中,我们将其用于我们的产品 (Cloud CMS)。其他人已将其用于其他 CMS 系统以及由 MongoDB 和 CouchDB 等支持的项目。因此,对其进行了大量研究。
回答by azy777
回答by liunian
回答by BuGless
I just recently stumbled upon Metawidget mentioned above, and I must say that I'm impressed. It looks a like the proper kitchensink-solution to go for.
我最近偶然发现了上面提到的 Metawidget,我必须说我印象深刻。它看起来像是合适的厨房水槽解决方案。
Then again, if you want something small and with zero dependencies, you could take a look at outperform. It's a small javascript form generator library that I recently wrote to support my own projects because I got fed up by the fact that all the form generators that I looked at either had a ton of dependencies, or were distinctly larger than my single page web-application.
再说一次,如果你想要一些小而零依赖的东西,你可以看看outperform。这是一个小型 javascript 表单生成器库,我最近编写了它来支持我自己的项目,因为我厌倦了这样一个事实,即我查看的所有表单生成器要么有大量的依赖项,要么明显大于我的单页 web-应用。
回答by Richard Kennard
May I humbly suggest Metawidget?
我可以虚心推荐Metawidget吗?
It creates UIs from JSON objects. It does not require JQuery, but has support for it. It also supports other object formats (such as JSON Schema, schemas over REST etc).
它从 JSON 对象创建 UI。它不需要 JQuery,但支持它。它还支持其他对象格式(例如 JSON 模式、基于 REST 的模式等)。