【问题标题】:ExtJS--creating multiple instances of the same form but with different names for fieldsExtJS--创建相同表单但字段名称不同的多个实例
【发布时间】:2014-11-16 18:39:15
【问题描述】:

我有一个 Ext.form.Panel。在表单项中,我有一个包含所有表单字段的容器。单击添加按钮后,我将该容器的另一行/实例插入到表单中。创建新实例时如何更改字段名称?例如,字段名称为 FIELD_1。当创建一个新实例时,id 喜欢将其更改为 FIELD_2 然后 FIELD_3 等等..

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

"FIELD_1":["Row1Val", "Row2Val", "Row3Val"], "FIELD_2":["Row1Val", "Row2Val", "Row3Val"]

我不想要这个。这就是为什么我需要在创建新实例时为字段名称添加后缀

谢谢

【问题讨论】:

    标签: javascript forms extjs


    【解决方案1】:

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

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-28
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多