ExtJS4中的Ext.getCmp不工作
我正在尝试创建一个组件并在控制器中访问它。但是,当通过id访问组件时,它不会返回组件。它总是返回未定义的。请找到下面的代码 在这里输入代码ExtJS4中的Ext.getCmp不工作,extjs,extjs4,Extjs,Extjs4,我正在尝试创建一个组件并在控制器中访问它。但是,当通过id访问组件时,它不会返回组件。它总是返回未定义的。请找到下面的代码 在这里输入代码 //Component creation in view layer as below Ext.define('MyApp.view.performance.grid.IFrameGridCmp', { extend: 'Ext.panel.Panel', alias: 'widget.crMainPanel', id:'mainP
//Component creation in view layer as below
Ext.define('MyApp.view.performance.grid.IFrameGridCmp', {
extend: 'Ext.panel.Panel',
alias: 'widget.crMainPanel',
id:'mainPanelId',
layout: {
align: 'stretch',
type: 'vbox'
},
border:0,
resizable: false,
forceFit: true,
autoWidth: true,
initComponent: function() {
Ext.apply(this, {
items: [
{
xtype:'panel',
flex:.02,
border:0
},
{
xtype:'crHeaderPanel',
flex:.05
},
{
xtype: 'crUpperPanel',
flex: 0.93
},
Ext.create('Ext.Component', {
autoEl: {
tag: 'iframe',
cls: 'x-hidden',
src: Ext.SSL_SECURE_URL
},
id:'FileDownloader',
height:0,
listeners: {
afterrender: function () {
this.getEl().on('load', function () {
console.log('loaded download frame');
});
}
},
load: function(config){
var e = this.getEl();
e.dom.src = config.url + (config.params ? '?' + Ext.urlEncode(config.params) : '');
e.dom.onload = function() {
Ext.getBody().unmask();
if(e.dom.contentDocument.body.childNodes[0].wholeText == '404') {
Ext.Msg.show({
title: 'Attachment missing',
msg: 'The document you are after can not be found on the server.',
buttons: Ext.Msg.OK,
icon: Ext.MessageBox.ERROR
});
}
};
}
})
]
});
this.callParent(arguments);
}
});
========================================
enter code here
//Accessing the controller as below in controller
views: ['performance.grid.IFrameGridCmp'],
//The below line gives error
var downloader = Ext.getCmp('FileDownloader');
downloader.load({
url: '/APXUI/data/json/xls?exportData='+Ext.JSON.encode(records)
});
嗯,在调用
Ext.getCmp()
请注意,
视图:['performance.grid.IFrameGridCmp'],
只是将该视图绑定到控制器的一种绑定,这意味着控制器将为您创建一个getter,仅此而已。您仍然需要通过调用.create()实例化视图
或Ext.widget('crMainPanel')
在控制器中,例如使用控件来处理它:
me.control({
'crMainPanel #FileDownloader': {
afterrender: me.addDownloader
}
});
不要使用Ext.getCmp(),它的速度非常慢,您将遇到许多问题。
不要使用id-最好使用itemId。
为什么需要从controller调用此函数?getCmp一点也不慢,事实上,它可能是查找组件的最快方法,而不是直接引用。但是,我同意最好避免在大型应用程序中使用它们。是的,你说得对,关于速度:)我不使用它,而且在我看来,一般来说速度很慢。此视频可以描述为什么不需要使用。我想@Evantimboli会知道这是一个核心开发人员;-)