【问题标题】:ExtJS Cannot read property 'addClass' of nullExtJS 无法读取 null 的属性“addClass”
【发布时间】:2020-08-29 05:41:43
【问题描述】:

我正在尝试将表单动态添加到另一个表单,但抛出错误:

未捕获的类型错误:无法读取 null 的属性“addClass”

我真的不明白,因为我可以添加 f.e. new Ext.Button({text: 'testing'})。 但是表格不能加?为什么?

小提琴是here

var frmTemplate = new Ext.form.FormPanel({
        border: false,
        items: [{
                layout: 'hbox',
                border: false,
                items: [

                    {
                        xtype: 'textfield',
                        emptyText: 'testing 123...',
                        hideLabel: true
                    }, {
                        xtype: 'button',
                        text: 'testiranje',
                        style: {
                            marginLeft: '10px'
                        }
                    }

                ]
            }

        ]
    });

    var form1 = new Ext.form.FormPanel({
        layout: 'fit'
    });

    form1.add(frmTemplate);

    form1.render(document.body);
    form1.doLayout();

【问题讨论】:

    标签: extjs


    【解决方案1】:

    只需将父级更改为 Ext.Panel 或将子级更改为 Ext.Panel:

    Ext.onReady(function () {
    
        var frmTemplate = new Ext.form.FormPanel({
            //var frmTemplate = new Ext.Panel({
            border: false,
            items: [{
                layout: 'hbox',
                border: false,
                items: [{
                    xtype: 'textfield',
                    emptyText: 'testing 123...',
                    hideLabel: true
                }, {
                    xtype: 'button',
                    text: 'testiranje',
                    style: {
                        marginLeft: '10px'
                    }
                }]
            }]
        });
    
        //var form1 = new Ext.form.FormPanel({
        var form1 = new Ext.Panel({
            layout: 'fit'
        });
    
        form1.add(frmTemplate);
    
        form1.render(document.body);
        form1.doLayout();
    
    });
    

    【讨论】:

    • 也许你知道这是为什么?为什么 Panel 有效而 Form 无效?
    • 不知道为什么..顺便问一下,为什么需要form in form?
    • 因为我是动态添加内容的。我收到必须显示的记录数组。非常感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    相关资源
    最近更新 更多