将数据保存到表单中的商店提交成功ExtJS

时间:2013-11-29 08:43:37

标签: forms extjs extjs4 submit

我有一个Form(Ext.form.FormPanel),它基本上是一个登录面板,有两个字段,如user_name和password,以及一个表单提交表单。现在我能够向我的php服务提交数据,该服务也返回数据,我能够看到action.result中的数据(这实际上是一个UserVO,其中包含user_name,password,user_type,user_id ......等字段)。

精确数据的PFB

id
    1

user_name
    "super@super.com"

password
    "cccccccc"

first_name
    "Super"

last_name
    "Super"

user_type
    "Super"

parent_id
    0

_explicitType
    "certification.vo.UserVO"

success
    true

现在我的问题是如何从action.result获取此结果数据,将其解析为Model类型并将其存储在我的应用程序中,以便在应用程序(Ext.application)中可用于其他视图使用。

我的用户模型类如下所示。

Ext.define('Certify.model.UserVO',{
    extend: 'Ext.data.Model',
    fields: ['id','user_name','password','first_name','last_name','user_type','parent_id','_explicitType']
});

我的申请如下。

Ext.application({
    requires : ['Ext.container.Viewport', 'Ext.form.FormPanel', 'Ext.Window', 'Ext.container.Container', 'Ext.Button', 'Ext.app.Controller'],
    name : 'Certify',
    appFolder : 'app',
    models: ['UserVO'],
    controllers : ['LoginController'],
    launch : function() {
        Ext.create('Ext.container.Viewport', {
            layout : {
                type : 'vbox',
                align : 'center',
                pack : 'center'
            },
            items : {
                xtype : 'loginview'
            }
        });
    }
});

此外,我的表单也会提交。

var callData = JSON.stringify(callDataObj);
                    Ext.getCmp('loginForm').getForm().submit({
                        url : url + "login_json/" + callData,
                        method : 'POST',
                        waitTitle : 'Connecting',
                        waitMsg : 'Sending data...',
                        success : function(form, action) {
                            Ext.Msg.alert('Status', 'Login Successful!', function(btn, text) {
                                if (btn == 'ok') {
                                    var redirect = './superuser.html';
                                    window.location = redirect;
                                }
                            });
                        },

1 个答案:

答案 0 :(得分:0)

由于您已拥有有效的模型,因此可以使用它来创建商店:

Ext.create('Ext.data.Store', {
    storeId    : 'myStore',
    model      : 'Certify.model.UserVO',
    [...]
}

提交登录表单后,您可以使用myForm.getValues()获取所有字段值,并使用它们向商店添加记录。从那里开始,您可以在应用程序的任何位置使用它。

http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store-method-add