1

我正在使用 ExtJS 3.4,我有一个mainDetailsFieldSet我想以两种形式使用的字段集,addFormPanel以及updateFormPanel. 我能够以addFormPanel表单形式获取字段集,但无法在 updateFormPanel 中获取它。我得到一条蓝线。我在这里找不到什么问题...有人可以帮我解决这个问题吗?

这是我的代码:

//带有文本字段和组合框的主字段集

  var clCombo = new Ext.form.ComboBox({
                    store: store,
                    fieldLabel: 'Name',
                    displayField: 'clName',
                    name: 'clName',
                    valueField: 'clName',
                    typeAhead: true,
                    mode: 'local',
                    triggerAction: 'all',
                    emptyText: 'Select Here'
          });
this.mainDetailsFieldSet = new Ext.form.FieldSet({
        title: 'Details',
        items:[
            {
                fieldLabel: ' Name',
                xtype: 'textfield',
                name: 'name'
                },clCombo
            ]
        });
var mainDetailsFieldSet = this.mainDetailsFieldSet ;

//addFormPanel,我在这里使用mainfieldset

this.addFormPanel = new Ext.form.FormPanel({
                title: 'Add Form',
                autoScroll: true,
                items:[
                    mainDetailsFieldSet ]
});

//updateformpanel,在这里我想再次添加相同的字段集

this.updateFormPanel = new Ext.form.FormPanel({
            autoScroll: true,
            items:[mainDetailsFieldSet]
        }); 

提前致谢

4

2 回答 2

2

您不能将一个实例渲染到不同的地方。

变体 A:如果您需要两次,则需要创建第二个实例。

this.comboCfg = {
      store: store,
      fieldLabel: 'Name',
      displayField: 'clName',
      name: 'clName',
      valueField: 'clName',
      typeAhead: true,
      mode: 'local',
      triggerAction: 'all',
      emptyText: 'Select Here'
};
this.mainDetailsFieldSet1 = new Ext.form.FieldSet({
    title: 'Details',
    items:[{
        fieldLabel: ' Name',
        xtype: 'textfield',
        name: 'name'
        },Ext.apply({xtype:'combo'},comboCfg)]
});
this.mainDetailsFieldSet2 = new Ext.form.FieldSet({
    title: 'Details',
    items:[{
        fieldLabel: ' Name',
        xtype: 'textfield',
        name: 'name'
        },Ext.apply({xtype:'combo'},comboCfg)]
});
var mainDetailsFieldSet1 = this.mainDetailsFieldSet1;
var mainDetailsFieldSet2 = this.mainDetailsFieldSet2;

this.addFormPanel = new Ext.form.FormPanel({
     title: 'Add Form',
     autoScroll: true,
     items:[mainDetailsFieldSet1]
});

this.updateFormPanel = new Ext.form.FormPanel({
    autoScroll: true,
    items:[mainDetailsFieldSet2]
}); 

变体 B:但是您可以做的是每次都删除添加实例。

this.addFormPanel = new Ext.form.FormPanel({
     title: 'Add Form',
     autoScroll: true
});
// before show
this.addFormPanel.add(mainDetailsFieldSet);
// before hide
this.addFormPanel.remove(mainDetailsFieldSet);

this.updateFormPanel = new Ext.form.FormPanel({
     autoScroll: true
});
// before show
this.updateFormPanel .add(mainDetailsFieldSet);
// before hide
this.updateFormPanel .remove(mainDetailsFieldSet);

注意xtype尽可能多地 使用带有 's 的配置,id如果不是严格需要,请不要自己定义任何配置。


变体 C:

this.comboCfg = {
      store: store,
      fieldLabel: 'Name',
      displayField: 'clName',
      name: 'clName',
      valueField: 'clName',
      typeAhead: true,
      mode: 'local',
      triggerAction: 'all',
      emptyText: 'Select Here'
};
this.mainDetailsFieldSetCfg = {
    xtype: 'fieldset',
    title: 'Details',
    items:[
       { xtype:'textfield',fieldLabel:' Name',name:'name'},
       Ext.apply({xtype:'combo'},comboCfg)
    ]
});

this.addFormPanel = new Ext.form.FormPanel({
     title: 'Add Form',
     autoScroll: true,
     items:[this.mainDetailsFieldSetCfg]
});

this.updateFormPanel = new Ext.form.FormPanel({
    autoScroll: true,
    items:[this.mainDetailsFieldSetCfg]
});
于 2014-12-10T11:06:04.893 回答
0

我很确定如果您在两个地方添加相同的元素,它只会以第一种形式呈现,而不会以另一种形式呈现。它将其视为错误。您需要为第二种形式的元素设置不同的 ID。两个字段集必须是由不同 ID 区分的单独实体。它们可以具有相同的配置,只要它们具有不同的 ID。

于 2014-12-09T16:06:54.923 回答