簡體   English   中英

extjs xtype按鈕樣式變量

[英]extjs xtype button style variable

我想將變量(btnWidth / bthHeight)設置為按鈕的width(height):

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

我該如何解決?

為此,您需要為panel使用initComponent方法。 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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM