提交表格 + ExtJS 4 中的网格
我有一个 Ext.form.Panel,其中包含一个网格和一些用于编辑网格中每一行的文本字段。它与此非常相似:http://dev. sencha.com/deploy/ext-4.0.2a/examples/writer/writer.html ,只是不涉及AJAX;我的数据存储是本地的。
如何通过标准 POST 提交网格行?
如果我只是执行 myForm.submit(),则会出现两个问题:
正在验证用于编辑网格行的字段。提交表单时应忽略它们。
没有提交来自网格的数据。
我看到的唯一解决方案是以某种方式阻止验证字段并创建一些包含每行数据的隐藏字段。还有更好的选择吗?
先感谢您!
I have an Ext.form.Panel containing a grid and some text fields for editing each row in the grid. It is very similar to this: http://dev.sencha.com/deploy/ext-4.0.2a/examples/writer/writer.html , only that there is no AJAX involved; my data store is local.
How can I submit the grid's rows via a standard POST?
If I simply do myForm.submit(), there are two issues:
The fields for editing the grid's rows are being validated. They should be ignored when submitting the form.
No data from the grid is being submitted.
The only solution I see is to somehow prevent the fields from being validated and create some hidden fields containing the data from each row. Is there any better option?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我使用的解决方案:
为了在提交时忽略表单中的某些字段,我重写了表单的 getFields() 方法。讨厌,我知道。在下面的代码中,具有“ignoreInMainForm”属性的字段将被忽略。
为了提交网格数据,我将所有行编码在一个 JSON 对象中,并添加到表单的 baseParams 中。
Here's the solution I used:
For ignoring certain fields from the form upon submitting, I've overwritted the getFields() method of the form. Nasty, I know. In the code below, the fields with an 'ignoreInMainForm' property will be ignored.
For submitting the grid's data, I encode all the rows in a single JSON object that I add in the form's baseParams.
这对我来说部分有效 - 在 ExtJS 4.0.2a 中,我无法添加到 baseParams,因此我触发了发送处理程序来执行以下操作:
这很有魅力(但不是很即插即用)。我必须在表单中创建一个隐藏字段(上面名为 roomLinks),上面的第二个 for 循环会找到该字段,并将该值替换为 JSON 格式的结果。
That partially worked for me - in ExtJS 4.0.2a, I couldn't add to the baseParams, so instead I triggered the send handler to instead do:
Which worked lie a charm (but isn't very plug-and-play). I had to create a hidden field (named roomLinks above) in the form, and the second for loop above finds that and replaces the value with the JSONed results.