如何使用ExtJs下的商店提交表单? [英] How do I submit a form using a store under ExtJs?
问题描述
有没有办法让表单提交在ExtJs 4下的商店中创建一个对象?
Is there a way to have a form submit create an object in a store under ExtJs 4?
对于我来说,这个网格完全是围绕着存储机制,我看到没有明显的方式将表单插入商店。但我最有可能只是想念一些东西。
It seems strange to me that the grid is built completely around the store mechanism and I see no obvious way to plug a form into a store. But I am most likely just missing something.
推荐答案
您可以使用以下代码在表单提交时将模型实例添加到商店:
You can add a model instance to a store upon form submit using this code:
onSaveClick: function()
{
var iForm = this.getFormPanel().getForm(),
iValues = iForm.getValues(),
iStore = this.getTasksStore();
iStore.add( iValues );
},
这是一个MVC控制器,所以这个
是控制器。
This is within an MVC controller, so this
is the controller.
对于模型编辑,您可以使用 loadRecord'将表单绑定到模型实例, / code>:
For model editing, you can 'bind' a form to a model instance using loadRecord
:
iFormPanel.loadRecord( this.selection );
然后,您可以使用 updateRecord()$ c更新模型实例$ c>:
iFormPanel.getForm().updateRecord();
只是为了好玩(可能有些帮助),它类似于以下代码: / p>
Just for fun (and as it might help some), it is similar to the following code:
onSaveClick: function()
{
var iForm = this.getFormPanel().getForm(),
iRecord = iForm.getRecord(),
iValues = iForm.getValues();
iRecord.set ( iValues );
},
如果您的商店有 autoSync:true
。将通过配置的代理进行更新(或创建)呼叫。如果没有autoSync,则必须手动同步您的商店。
If your store is has autoSync: true
. An Update (or Create) call will be made via the configured proxy. If there's no autoSync, you'll have to sync your store manually.
这篇关于如何使用ExtJs下的商店提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!