【发布时间】:2012-07-11 22:02:59
【问题描述】:
您好,我想在更改完成时显示类似于警告标志的图像,然后我有一个像这样的页脚面板,带有标志:
Ext.define('footerPanel', {
extend: 'Ext.panel.Panel',
cls: 'fastec_background',
height: 24,
autoScroll: false,
border: false,
layout: {
type: 'border'
},
id: 'panel_footerFastec',
initComponent: function () {
var me = this;
Ext.applyIf(me, {
items: [{
margin: '5 5 0 20',
xtype: 'label',
region: 'center',
html: '<a>© 2012 FASTEC GmbH, Paderborn, Germany - </a><a target="_blank" href="http://www.easyoee.de">www.easyOEE.de</a> <a target="_blank" href="http://www.fastec.de">www.fastec.de</a>'
}, {
xtype: 'container',
region: 'east',
layout: 'table',
id: 'cont_footer_icons',
items: [{
xtype: 'image',
id: 'configchangedIcon',
height: 16,
margin: '5 0 5 0',
width: 16,
maxHeight: 20,
dock: 'right',
maxWidth: 20,
scale: 'large',
src: 'files/images/disk_blue.png',
hidden: true
}, {
xtype: 'image',
height: 16,
id: 'errorIcon',
margin: '5 0 5 0',
width: 16,
dock: 'right',
maxHeight: 20,
maxWidth: 20,
scale: 'large',
src: 'files/images/error16.gif',
hidden: true
}]
}]
});
me.callParent(arguments);
}
});
我的想法是我有一个通用函数,我可以在任何地方调用它并显示或隐藏图标,但不幸的是我调用了这个函数并没有任何反应:
changeIconVisibility = function(str, value) {
try {
switch(str){
case 'configchangedIcon':
var img = Ext.getCmp('configchangedIcon');
if(value){
img.setVisible(true);
}else{
img.setVisible(false);
}
break;
}
} catch (e) {
Ext.msg.alert(e);
}
}
我尝试直接调用组件和 setVisible(true) 也没有任何反应。
【问题讨论】:
-
如果隐藏配置设置为 false,您是否看到图标? setVisible() 是否会被调用(比如将 console.log() 放在它之后)?
-
图标在调用setVisible()之前隐藏配置为真,调用后隐藏配置为假,但不显示图标。
-
是的,但是如果您将隐藏配置设置为false,您可以在应用程序加载时看到图标吗?这只是为了检查您的布局/图像位置等是否有问题。
-
在您的应用程序中打开 javascript 控制台(Firebug、开发者工具等),然后执行
Ext.getCmp('configchangedIcon');。它是否有任何结果(除了 null 或 undefined)? -
hidden和visible不是同一个属性,这就是切换它不起作用的原因。
标签: javascript events extjs extjs4