当 init 函数创建视口时,如何执行 Ext.Require 操作?
我试图为加载器“要求”一些代码,但我当前的 onready 函数让我对要求感到悲伤(它抱怨尚未创建视口)。由于我在创建时将内容分配给视口,因此我实际上不能要求我填充的内容(除非我创建视口然后向其分配内容,但是,嗯)。
我到底如何使用这样的函数 Ext.require[] 呢? (或者我如何重构这个函数,使其以相同的方式执行,同时让我在数组上运行 Ext.Require ?)
Host=function(){
return{
centerPanelId: 'mainLayoutCenter',
init: function(){
//Enable the loader for dynamic loading of js, only dev pls
Ext.Loader.setConfig({enabled:true});
Ext.QuickTips.init(); //ext needs this
Ext.Loader.setPath("bleh","js/bleh"); //Project paths for the loaders
if(!window.User){
this.initialContent = Ext.create('bleh.Login');
}
//Our default View
//this.initialContent = Ext.create('bleh.panel.Register');
this.currentContent=this.initialContent;
//Instantiate a viewport
this.viewport = Ext.create("bleh.viewport",{
initialContent : this.initialContent
,host:this
});
//init function, to hande events for HTML elements etc
//bleh.init();
}
,setContent: function( contentPanel ){
var center = Ext.getCmp(this.centerPanelId);
if ( this.currentContent ) { center.remove(this.currentContent); }
this.currentContent = contentPanel;
center.add(this.currentContent);
center.doLayout();
this.currentContent.show();
}
}
}();
Ext.onReady( Host.init, Host );
I'm trying to 'require' some code for the loader, but my current onready function is giving me grief with the require ( it complains about the viewport not being created yet ). Since I assign content to the viewport on creation, I cant really require the content that I populate ( unless I create the viewport and then assign stuff to it, but meh ).
How the heck do I Ext.require[] with a function like this? ( or how can I restructure this function so it performs in the same way, whilst letting me run Ext.Require on an array?)
Host=function(){
return{
centerPanelId: 'mainLayoutCenter',
init: function(){
//Enable the loader for dynamic loading of js, only dev pls
Ext.Loader.setConfig({enabled:true});
Ext.QuickTips.init(); //ext needs this
Ext.Loader.setPath("bleh","js/bleh"); //Project paths for the loaders
if(!window.User){
this.initialContent = Ext.create('bleh.Login');
}
//Our default View
//this.initialContent = Ext.create('bleh.panel.Register');
this.currentContent=this.initialContent;
//Instantiate a viewport
this.viewport = Ext.create("bleh.viewport",{
initialContent : this.initialContent
,host:this
});
//init function, to hande events for HTML elements etc
//bleh.init();
}
,setContent: function( contentPanel ){
var center = Ext.getCmp(this.centerPanelId);
if ( this.currentContent ) { center.remove(this.currentContent); }
this.currentContent = contentPanel;
center.add(this.currentContent);
center.doLayout();
this.currentContent.show();
}
}
}();
Ext.onReady( Host.init, Host );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够在这段代码之前要求您需要的任何内容。它已经包装在 onReady 块中,因此只要您需要它们,默认情况下所有依赖项都可用之前它不会被执行。只需将其添加到您的代码上方:
You should be able to just require whatever you need before this block of code. It's already wrapped in an
onReady
block, so it will not be executed until all dependencies are available by default, as long as you require them. Just add this above your code: