Extjs 3.3动态地将字段添加到表单中,并设置它们的标签宽度

Extjs 3.3 dynamically add fields to a form and set their labels width

本文关键字:设置 标签宽度 表单 动态 字段 添加 Extjs      更新时间:2023-09-26

在表单上调用doLayout后,我需要设置labelWidth属性。

表单呈现后,对do布局的序列请求似乎忽略了表单的labelWidth属性,并设置为100px默认值。

Nipendo.ProformaInvoice.View = Ext.extend(Ext.FormPanel,{
     constructor: function (config) {
        if (!config) {
            Nipendo.showError({ title: 'Error', message: 'A error occurred while loading the invoice view. A configuration element is missing.' });
            return;
        }
        if (!config.invoice) {
            Nipendo.showError({ title: 'Error', message: 'A error occurred while loading the invoice view. The invoice element is missing.' });
            return;
        }
    this.topToolbar = this.creatTopToolbar();
    this.invoice = config.invoice;
        var items = this.createDefaultLayout();
        config = Ext.apply({
            labelWidth: 140,
            bodyStyle: 'padding:2px 5px;',
            autoScroll: true,
            tbar: this.topToolbar,
            items: items
        }, config);
        Nipendo.ProformaInvoice.View.superclass.constructor.call(this, config);
    }, // eo constructor
    // private
    handelBackToDefaultView: function (switchToView) {
         if (this.currentViewName == 'sidebyside') {
             this.removeAll();
             this.currentViewName = switchToView;
             this.add(this.createDefaultLayout());
             this.doLayout();
         }
         this.currentViewName = switchToView;
     }, //eo handelBackToDefaultView
})

在调用handelBackToDefaultView之后,所有标签都被设置为100px。

感谢的帮助

我自己发现了这个问题,

问题是,我创建的新并排布局确实创建了一个新面板作为表单的第一项,该面板缺少所有内部字段固有的labelWidth属性。