extjs xtype按钮样式变量

问题描述 投票:0回答:1

我想把变量(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

我该如何解决?

javascript variables extjs extjs4 width
1个回答
2
投票

为此,你需要使用initComponent方法为panel。在panel中,您将定义自定义配置,您可以进入initComponent方法。

在这个FIDDLE中,我使用panelbuttoninitComponent方法创建了一个演示。我希望这能帮助您或指导您实现您的要求。

代码片段

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');
© www.soinside.com 2019 - 2024. All rights reserved.