如何在ExtJs代理商店中发送登录信息?

时间:2016-04-27 15:18:45

标签: java extjs

如何发送login(username)作为store.load()方法的参数。我想在服务器上登录并仅加载此用户数据。 我在NotesGrid initComponent方法中调用load方法,但是我无法从那里获取登录数据(或者我不知道如何执行此操作)。 我也尝试在LoginController的onLoginSuccess方法中调用store.load(),但它根本不起作用。

我知道我可以使用store.load({params:{login:' username'}})

但是如何使用store.load()调用从LoginForm发送登录信息

的LoginController:

new

GridView的:

Ext.define('MVC.controller.LoginController', {
extend: 'Ext.app.ViewController',
alias: 'controller.login',

requires: [
    'MVC.view.Register',
    'MVC.view.Main'
],

views:[
  'MVC.view.Login'
],

init : function() {
    //control function makes it easy to listen to events on
    //your view classes and take some action with a handler function
    this.control({
        //when you click Submit button
        'login button[action=login]' : {
            click : this.onLoginClick
        }
    });
},

onLoginClick: function (button) {

    // This would be the ideal location to verify the user's credentials via
    // a server-side lookup. We'll just move forward for the sake of this example.
    var form = button.up('form').getForm();

    Ext.Ajax.request({
        url: 'login',
        method: 'POST',
        params: {
            loginData: Ext.encode(form.getValues())
        },
        scope: this,
        //method to call when the request is successful
        success: this.onLoginSuccess,
        //method to call when the request is a failure
        failure: this.onLoginFailure
    });
},

onRegisterClick: function () {
    this.getView().destroy();

    Ext.create({
        xtype: 'register'
    }).show()
},

onLoginFailure: function (err) {
    //Alert the user about communication error
    Ext.MessageBox.alert('Error occured during Login', 'Please try again!');
},

onLoginSuccess: function (response, opts) {
    //Received response from the server
    response = Ext.decode(response.responseText);
    if (response.success) {
        Ext.MessageBox.alert('Successful Login', response.message);

        this.getView().destroy();

        Ext.create({
            xtype: 'main'
        });

    }
    else {
        Ext.MessageBox.alert('Login failed', response.message);
    }
}
});

商店:

Ext.define('MVC.view.NotesGrid', {
extend: 'Ext.grid.Panel',
xtype: 'notesGrid',

title: 'Note-list',

//  store: 'Notes',
store: 'TestStore',

initComponent: function(){
    this.callParent();
    this.on('render', this.loadStore, this);
},

loadStore: function() {
    this.getStore().load();
},

columns: [
    {
        text: 'Name',
        dataIndex: 'name',
        flex: 1
    },
    {
        text: 'Creation Date',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'createDate',
        flex: 1
    }, {
        text: 'Last Modified',
        xtype: 'datecolumn',
        format: 'd-m-Y',
        dataIndex: 'modifiedDate',
        flex: 1
    }, {
        text: 'Text',
        dataIndex: 'noteText',
        flex: 3
    }
]
});

0 个答案:

没有答案