使用ExtJS getView构建登录不是一个函数

使用ExtJS getView构建登录不是一个函数,extjs,extjs5,Extjs,Extjs5,我试图创建一个登录使用extjs与PHP,但我坚持这个问题 TypeError: this.getView is not a function this.getView().destroy(); 这是我的密码 我不知道为什么会出错,我只是试着按照sencha docs中的教程进行操作 buttons: [{ text: 'Login', formBind: true, listeners: { cli

我试图创建一个登录使用extjs与PHP,但我坚持这个问题

TypeError: this.getView is not a function


this.getView().destroy();
这是我的密码

我不知道为什么会出错,我只是试着按照sencha docs中的教程进行操作

 buttons: [{
            text: 'Login',
            formBind: true,

        listeners: {
           click: function() {
                                        var form = Ext.getCmp('login').getForm();

                                        if(form.isValid()) {
                                                form.submit({
                                                        url : 'data/login.php',
                                                        method : 'POST',                                                      

                                                           success:function(){ 
                                                            this.getView().destroy();
                                                            Ext.widget('app-main');
                                                                },
                                                            failure: function() {
                                                                      obj = Ext.util.JSON.decode(response.responseText); 
                                                                        Ext.Msg.alert('Login Failed!', obj.errors); 
                                                            }
                                                });
                                        }
                               }              
        }
        }]   

您是否尝试过
console.log(此)
?我想不是

这始终取决于上下文。这里的上下文不是视图,而是Ext.Ajax.request(如果我没有弄错的话),在它的
success
函数中,您试图破坏视图

这就是为什么我不在代码中使用它,即使对于我所处的上下文中的外行读者来说,它也不是完全显而易见的

编辑:因为代码在注释中看起来很糟糕,所以我把它添加到这里。 根据原始Ext来源,答案为

click: function() {
    var me = this;
    var form = Ext.getCmp('login').getForm();

    if(form.isValid()) {
        form.submit({
            url : 'data/login.php',
            method : 'POST',

            success:function(){ 
                me.getView().destroy();
                Ext.widget('app-main');
            },
            failure: function() {
                obj = Ext.util.JSON.decode(response.responseText);
                Ext.Msg.alert('Login Failed!', obj.errors);
            }
        });
    }
}
而我个人会使用

click: function(btn) {
    var form = Ext.getCmp('login').getForm();

    if(form.isValid()) {
        form.submit({
            url : 'data/login.php',
            method : 'POST',

            success:function(){ 
                btn.up('window').hide();
                Ext.widget('app-main');
            },
            failure: function() {
                obj = Ext.util.JSON.decode(response.responseText);
                Ext.Msg.alert('Login Failed!', obj.errors);
            }
        });
    }
}

您好,先生,您有什么想法来解决或如何实现我想做的事情吗?我很想创建一个登录,我只是一个初学者谢谢先生!我尝试了第一个,但我没有工作,然后我尝试了第二个,它的工作!谢谢你的时间