ExtJS 从数据库加载表单项/字段
我在这里使用 ExtJS 3。我想用要提交的字段从数据库填充表单面板。基本上,我不知道我的表单将具有的女巫字段,并且我想从数据库生成所有表单面板项目。我可以生成一个 JSON 字符串作为来自 PHP 文件的响应传递,其中包含字段和所有内容,但我需要知道如何在 ExtJS 中使用它。
有什么帮助吗?
谢谢。
I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don't know witch fields my form will have and I want to generate all formpanel items from database. I could generate a JSON string to be passed as the response from the PHP file with the fields and everything but I need to know how to work with this in ExtJS.
Any help ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须以 ExtJS 可以理解的格式加载和发送字段。如果您不介意直接耦合到 ExtJS 格式,最简单的方法是在后端生成 ExtJS 模板样式。在这种情况下,您的 php 脚本将生成如下内容:
显然,您可以重新排列它,以便在循环中预先构建“items”数组,并且您可以根据需要添加任意数量的项目。
此外,根据您的设置方式,您还可以仅返回项目数组并将它们动态添加到表单中,从而无需发送“new Ext.form..etc”部分,并解耦您的代码好一点了。就我个人而言,这就是我会走的路。
编辑:
在回复您的评论时,如果您以正确的 ExtJS 结构返回 JSON 数组,您需要做的就是使用“panel.add(myItems);” [1] 方法,并且可能调用“panel.doLayout();”强制它重新渲染得很好。
查看有关“组件”[2] 的详细信息,了解 xtype 的工作原理。
[1] http://www.extjs.com/部署/dev/docs/?class=Ext.form.FormPanel
[2] http://www.extjs.com/deploy/dev/docs/?class=Ext.Component
You're going to have to load and send the fields in a format ExtJS understands. The simplest way, if you don't mind coupling directly to the ExtJS format, would be to generate the ExtJS template style on the backend. In that case, your php script would generate something like this:
Obviously, you could rearrange this so the "items" array is built up beforehand in a loop, and you can add as many items as you need.
Also, depending on how you set this up, you can also just return the array of items and add them to the form on the fly, removing the need to send the "new Ext.form.. etc" portion, and decoupling your code a little better. Personally, that's the way I'd go.
Edit:
In reply to your comment, if you return the JSON array in a proper ExtJS structure, all you'll need to do is use the "panel.add(myItems);" [1] method, and possibly a call to "panel.doLayout();" to force it to re-render nicely.
Check out the details on "components" [2] for how the xtype works.
[1] http://www.extjs.com/deploy/dev/docs/?class=Ext.form.FormPanel
[2] http://www.extjs.com/deploy/dev/docs/?class=Ext.Component
我知道这是一篇旧帖子,但无论如何我都会把它顶起来,因为它首先出现在我的 Google 搜索中。
我很幸运从 Ext.Ajax.request 返回一个 JSON 字符串, eval() 它(我知道,我知道,邪恶 - 但它有效并且 Ext.Decode 无论如何使用 eval) - 然后将 eval 的结果传递到Panel.add(Ext.ComponentManager.create(eval_result));
希望这对某人有帮助。
I know this is an old post, but I'll bump it anyways because it came up first in my Google Search.
I have had luck with returning a JSON String from an Ext.Ajax.request, eval() it (I know, I know, evil - but it works and Ext.Decode uses eval anyways) - then pass the results of the eval into Panel.add(Ext.ComponentManager.create(eval_result));
Hope this helps someone.