控制器在从Main.js中删除后找不到视图

控制器在从Main.js中删除后找不到视图

问题描述:

我对Sencha很新,所以这可能是一个新手错误:)控制器在从Main.js中删除后找不到视图

我试图在Sencha中实现页面导航。以下场景工作。

我有一个主屏幕和登录屏幕的Main.js。当我输入凭据时,我将转发给Home.js.

但是,现在我想从主窗口中删除主页,因为它只能在登录后显示。但是,从Main.js中删除xtype home后,无法再找到它。我不明白为什么。

Main.js

config : { 
    tabBarPosition : 'bottom', 

    items : [{ 
     xtype : 'startview', 
    }, { 
     xtype : 'contactform' 
    }, { 
     xtype : 'loginform' 
    }, { 
     xtype : 'createaccountform' 
    }, { 
     xtype : 'homeview' REMOVING THIS MAKES THE HOME undefined in the controller 
    }] 
} 

我控制器

Ext.define("MyApp.controller.LoginController", { 
extend : "Ext.app.Controller", 

xtype : 'logincontroller', 

requires : ['Ext.app.Router', 'MyApp.view.Home'], 

config : { 
    refs : { 
     loginForm : "#loginFormPanel", 
     home : 'homeview' 
    }, 

    routes : { 
     login : 'authenticateuser' 
    }, 
    control : { 
     'button[action=login]' : { 
      tap : "authenticateUser" 
     } 
    }, 
    views : ['Login', 'Home'] 
}, 

authenticateUser : function(button) { 

      **// WHEN REMOVING xtype: homeview from MAIN this getter returns undefined (??)** 
    var activeView = this.getHome(); 

    this.getLoginForm().submit({ 
     url : 'php/process_login.php', 
     method : 'POST', 
     success : function(form, result) { 

      alert('Success and moving to home ' + activeView); 
      Ext.Viewport.setActiveItem(activeView); 
     }, 
     failure : function(form, result) { 

      alert('2'); 

      Ext.Msg.alert('Error', 'failure....' + result); 
     } 
    }); 
} 
}); 

Home.js

Ext.define('MyApp.view.Home', { 
extend : 'Ext.tab.Panel', 
id : 'home', 
xtype : 'homeview', 
requires : ['Ext.TitleBar', 'Ext.Video'], 
config : { 
    title : 'Home', 
    iconCls : 'home', 
    tabBarPosition : 'bottom', 

    items : [{ 
     xtype : 'searchview', 
    }, { 
     xtype : 'profileview' 
    }, { 
     xtype : 'messagesview' 
    }, { 
     xtype : 'sensesview' 
    }] 

} 

});

app.js

views : ['Start', 'Main', 'Contact', 'Login', 'CreateAccount', 'Home', 'Messages', 'Profile', 'Search', 'Senses'], 

controllers : ['LoginController'], 

所以,我怎么能保证我仍然可以在控制器首页参考(从后取出主)?

感谢您的帮助, 科恩

你想给HomeitemId而不是id的。

Ext.define('MyApp.view.Home', { 
    extend : 'Ext.tab.Panel', 
    itemId : 'home', 
    xtype : 'homeview', 
    ... 
}); 

现在在你的控制器,你要像这样引用它:

... 
config : { 
refs : { 
    loginForm : "#loginFormPanel", 
    home : { 
      autoCreate: true, 
      selector: '#home', 
      xtype: 'homeview' 
     } 
}, 
... 
+0

感谢,这是它!与选择器的自动创建部分:) – 2013-02-26 17:31:50