Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS——创建同一表单的多个实例,但字段名称不同_Javascript_Forms_Extjs - Fatal编程技术网

Javascript ExtJS——创建同一表单的多个实例,但字段名称不同

Javascript ExtJS——创建同一表单的多个实例,但字段名称不同,javascript,forms,extjs,Javascript,Forms,Extjs,我有一个Ext.form.Panel。在表单项中,我有一个包含所有表单字段的容器。单击add按钮后,我将该容器的另一行/实例插入表单中。创建新实例时,如何更改字段名?例如,字段名为字段_1。创建新实例时,我想将其更改为字段_2,然后是字段_3,依此类推 因为在提交时,当我这样做时;这将按字段名返回数组中所有实例的所有表单值: "FIELD_1":["Row1Val", "Row2Val", "Row3Val"], "FIELD_2":["Row1Val", "Row2Val", "Row3Val

我有一个Ext.form.Panel。在表单项中,我有一个包含所有表单字段的容器。单击add按钮后,我将该容器的另一行/实例插入表单中。创建新实例时,如何更改字段名?例如,字段名为字段_1。创建新实例时,我想将其更改为字段_2,然后是字段_3,依此类推

因为在提交时,当我这样做时;这将按字段名返回数组中所有实例的所有表单值:

"FIELD_1":["Row1Val", "Row2Val", "Row3Val"], "FIELD_2":["Row1Val", "Row2Val", "Row3Val"]
我不想要这个。这就是为什么我需要在创建新实例时为字段名添加后缀的原因


谢谢,这很简单。您可以保留一个全局计数器来管理它,当您单击“添加”按钮时,计数器会不断增加

var number_of_row = 0;//you may choose to keep it global or of controller scope

function : addContainer(self){
     var data = Ext.create('Ext.container.Container', {
    layout: {
        type: 'hbox'
    },
    width: 400,
    },
    items: [{
        xtype: 'textfield',
        name: 'FIELD_'+(++number_of_row),
        id: 'FIELD_'+(++number_of_row)
    },
      //your other items
    ]
});
//your code to add this container to the form panel.
}