0

我有一个包含项目和按钮“添加”的表单,用于将字段动态添加到表单(复制第一个字段)。链接到按钮的功能是什么这是我的代码:

     var form new Ext.form.FormPanel({
            items           : [{
                xtype: 'fieldcontainer',
                combineErrors: true,
                msgTarget : 'side',
                layout: 'hbox',
                items: [{
                    xtype       : 'displayfield',
                    margin      : '0 10 0 0'
                },{
                    xtype       : 'button',
                    text        : 'select'
                }]
            }]
            ,buttons: [{
              text    : 'Add field'
            }]
        })
4

1 回答 1

0

I think you should define click function on button( or give an itemId to button and define a function in controller, where you can access form object items array and add a dynamic 'fieldcontainer' object to form. Refer below snippet:

In View:

,buttons: [{
          text    : 'Add field',
          itemId : 'addField'
        }

In controller:

refs : [{
    selector : 'viewport form',
    ref : 'myForm'
},
init : function(){
    this.control({
        '#addField':{
            click : this.addFieldContainer
        }
        });

},

addFieldContainer: function(){
var form = this.getMyForm();
form.items.push({
            xtype: 'fieldcontainer',
            combineErrors: true,
            msgTarget : 'side',
            layout: 'hbox',
            items: [{
                xtype       : 'displayfield',
                margin      : '0 10 0 0'
            },{
                xtype       : 'button',
                text        : 'select'
            }]
        });

}

Hope this helps.

于 2016-02-01T16:47:10.880 回答