简体   繁体   English

如何在ExtJS中动态更改面板的填充?

[英]How to dynamically change padding of a panel in ExtJS?

I want to change the panel's padding value after resize event. 我想在调整大小事件后更改面板的填充值。

{
    xtype : 'panel',
    flex : 10,
    layout : {
        type : 'hbox',
        align : 'stretch',
        padding : '0 5 0 5'
    },
    listeners:{
        resize:'resizePanel'
    },
}

There is resizePanel function: 有resizePanel函数:

resizePanel:function(target, width, height, oldWidth, oldHeight, eOpts){
        target.padding='0 ' + width / 7 + ' 0 ' + width / 7;
        target.doLayout();
    },

But this function doesn't change anything. 但是此功能没有任何改变。 Do you have any suggestion? 你有什么建议吗?

The target param in that function will be an Ext Panel instance which doesn't have a padding property. 该函数中的目标参数将是一个没有padding属性的Ext Panel实例。

Instead you should get to the underlying element, something like target.el or target.getEl() which will return you the Ext Element instance for the panel. 相反,您应该使用基础元素,例如target.el或target.getEl(),它们将为您返回面板的Ext Element实例。

If you look at the Ext Element in the api docs you can use the setStyle function. 如果您查看api文档中的Ext元素,则可以使用setStyle函数。 So as an example you could do 因此,您可以做一个例子

target.getEl().setStyle('padding','0 ' + width / 7 + ' 0 ' + width / 7) target.getEl()。setStyle('padding','0'+ width / 7 +'0'+ width / 7)

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM