我想将变量(btnWidth/bthHeight)放到按钮的宽度(高度)上:
Ext.define(
'TestPanel', {
extend: 'Ext.Panel',
width: 300,
height: 35,
btnHeight: 25,
btnWidth: 25,
items: [{
xtype: 'button',
width: btnWidth,
height: btnHeight,
}, {
xtype: 'button',
width: btnWidth,
height: btnHeight,
}
}这是错误消息:
Uncaught TypeError: Cannot read property 'btnWidth' of undefined问题
我怎么才能修好它?
发布于 2017-12-27 05:36:16
为此,您需要为initComponent使用panel方法。在panel中,您将定义自定义配置,并且可以进入initComponent方法。
在这个小提琴中,我使用panel、button和initComponent方法创建了一个演示。我希望这将有助于您或指导您实现您的要求。
代码片段
Ext.define('TestPanel', {
extend: 'Ext.panel.Panel',
bodyPadding: 5,
width: 300,
btnHeight: 38,
btnWidth: 50,
title: 'Buttons example',
initComponent: function (config) {
var me = this,
btnWidth = me.btnWidth,
btnHeight = me.btnHeight;
me.items = [{
xtype: 'button',
text: 'Button 1',
width: btnWidth,
height: btnHeight,
margin: 10
}, {
xtype: 'button',
text: 'Button 1',
width: btnWidth,
height: btnHeight
}];
me.callParent(arguments);
},
renderTo: Ext.getBody()
});
//Create component
Ext.create('TestPanel');https://stackoverflow.com/questions/47986150
复制相似问题