动态添加新字段到现有的表单面板

时间:2013-04-16 05:56:27

标签: extjs4.1

我想通过拖放动态地将容器(layout:hbox)内的新字段添加到FormPanel。

在表单面板中删除时,我可以动态添加字段。 但我想补充一下他们放弃的位置。

var dynamicField = Ext.create('Ext.container.Container',{
                            layout : 'hbox',

                             items: [{
                                                                xtype:'textfield',
                                                                fieldLable:'Test'

                                                           }, {
                                     xtype : 'image',
                                     src : 'images/cancel.png',
                                     hidden : true

                                  }]
                                      });


                          formPanel.add(dynamicField);

                               //   tried    dynamicField.showAt(e.getXY());

with dynamicField.showAt(e.getXY())没有运气// e是事件对象

任何人都可以建议我如何实现?

此致 URL

1 个答案:

答案 0 :(得分:0)

sencha提供了一个示例示例http://docs.sencha.com/extjs/4.1.3/#!/example/dd/dragdropzones.html。在这里我们正在创建一个自定义可删除区域,我们可以添加任何内容。检查此样本的代码。

 onNodeDrop : function(target, dd, e, data){
        var rowBody = Ext.fly(target).findParent('.x-grid-rowbody-tr', null, false),
            mainRow = rowBody.previousSibling,
            h = gridView.getRecord(mainRow),
            targetEl = Ext.get(target);

        targetEl.insert(<your control>); // here we can add control directly into it.
        return true;
    }

了解拖拽和滴,有一个很好的指南:http://docs.sencha.com/extjs/4.1.3/#!/guide/drag_and_drop

相关问题