【问题标题】:Save data into Store from Form Submit success ExtJS将数据从表单提交成功 ExtJS 保存到 Store
【发布时间】:2013-11-29 08:43:36
【问题描述】:

我有一个表单(Ext.form.FormPanel),它基本上是一个登录面板,有两个字段,如用户名和密码,以及一个提交表单的按钮。现在我可以向我的 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;
                                }
                            });
                        },

【问题讨论】:

    标签: forms extjs extjs4 submit


    【解决方案1】:

    由于您已经有一个有效的模型,您可以使用它来创建商店:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-24
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 2011-07-05
      • 1970-01-01
      相关资源
      最近更新 更多