0

我正在使用 extjs 3.4 添加添加此代码以在字段集中添加/删除键值对但无法正常工作它是动态添加字段但是当我们删除此浏览器时给出无限循环错误并且在一段时间后也给出了字段以下错误:

TypeError: this.dom is undefined 这是我的代码:

//这个js仅供测试

Ext.onReady(function(){

    Ext.QuickTips.init();
    function addressCounter(incr) {
        if (!this.no) {
            this.no = 0;
        } else {
            this.no = this.no + 1;
        };
    };
    var counter = new addressCounter();
    console.log(counter.no);
    var roomPanel = new Ext.form.FormPanel({
       renderTo:"sid",
        id: "roomFP",
        baseCls: 'x-plain',
        labelWidth: 120,
        defaultType: 'textfield',
        monitorValid:true,
        bodyStyle: ' padding: 15px; background-color: #ffffff' ,
        items:[
        {
            xtype: 'fieldset',
            title: 'Room Properties',
            collapsible: true,
            id:'roompropertiesId',
            items:[new Ext.Button({
                text:'Add Property',
                handler: function(item){
                    var fieldset  = Ext.getCmp('roompropertiesId');
                    if(fieldset.items.length >5){
                        Ext.MessageBox.alert('Add Property','only five fields has been added');
                        return;
                    } 
                    counter.no = counter.no + 1;
                    var a = fieldset.add({
                        xtype            : 'compositefield'
                        ,
                        id                : 'compositefieldId'+counter.no
                        ,
                        name                : 'name'+counter.no
                        ,
                        height            : 22
                        ,
                        autoDestroy    : true
                        ,
                        items            : [{
                            name        : 'key'+counter.no
                            ,
                            fieldLabel    : "Key",
                            id                : 'keyFieldId'+counter.no
                            ,
                            xtype        : 'textfield'
                            ,
                            width        : 50
                            ,
                            height        : 22
                            ,
                            allowBlank    : true
                        },{
                            name        : 'value'+counter.no
                            ,
                            xtype        : 'textfield',
                            id           : 'valueFieldId'+counter.no
                            ,
                            fieldLabel    : 'Value'
                            ,
                            width        : 50
                            ,
                            allowBlank    : true
                        },{
                            xtype    : 'displayfield',
                            id:'removeFieldId'+counter.no,
                            html    : '<div class="img-delete" onclick="removeFormFields(\''+counter.no+'\');"><a href="#">Remove</a></div>'
                            ,
                            height    : 16
                        }]
                    });
                    fieldset.doLayout();
                    removeFormFields = function(id) {
                        Ext.getCmp('compositefieldId'+id).destroy();
                    }
                }
            })]
        }
        ],
        listeners : {
            render : function(form){
            }
        },
       });


});
4

1 回答 1

2

看起来它是 Ext JS 中的错误。当你把 normalContainer而不是CompositeFieldthen 它工作正常。我发现CompositeField子字段在创建时被添加到BasicForm( FormPanel.getForm) 中CompositeField,但没有被删除。这会导致,例如,BasicForm验证引用被破坏的字段,并导致错误。IMO 你可以自由地从 切换CompositeFieldContainer.

于 2013-10-15T11:18:00.790 回答