如何在Ext JS中以弹窗形式显示一个Ext.FormPanel?

3
我可以使用Ext JS创建一个 "确认框",如下所示:
enter image description here
使用以下代码:
...
listeners: {
    'afterrender' : function(p) {
        p.header.on('click', function(e, h) {
            Ext.MessageBox.confirm('Confirm', 'Are you sure you want to EDIT this?', function(btn) {
                var button_answer = new Ext.Panel({
                    title: 'Invoice Address',
                    width: 290,
                    height: 200,
                    html: 'you clicked the ' + btn + ' button for EDIT',
                    frame: true,
                    border: true,
                    header: true
                });
                replaceComponentContent(small_box_upper_left, button_answer, true);
            });
        }, p, {
            delegate: '.panel_header_icon2',
            stopEvent: true
        });
    },
 ...

我该如何创建一个带有遮罩背景的弹出框并在其中放置 Ext.FormPanel,类似于这个例子但不是 MessageBox?例如,我应该如何将此代码放入带有遮罩背景的弹出框中?
new Ext.FormPanel({
        frame:true,
        labelWidth: 90,
        labelAlign: 'right',
        title: 'Orderer Information',
        bodyStyle:'padding:5px 5px 0',
        width: 300,
        height: 600,
        autoScroll: true,
        itemCls: 'form_row',
        defaultType: 'displayfield',
        items: [{
                fieldLabel: 'Customer Type',
                name: 'customerType',
                allowBlank:false,
                value: 'Company'
            },{
                fieldLabel: 'Company',
                name: 'company',
                value: 'The Ordering Company Inc.'
            },{
                fieldLabel: 'Last Name',
                name: 'lastName',
                value: 'Smith'
            }]
    });
3个回答

9

您可以使用窗口来实现,因为MessageBox没有任何配置选项来添加面板。

要显示遮罩,只需将config选项modal设置为true即可。

 win = new Ext.Window(
    {
        layout: 'fit',
        width: 500,
        height: 300,
        modal: true,
        closeAction: 'hide',
        items: new Ext.Panel(
        {
           items: //Your items here
        })
    });

5
我发现一种非常简单的方法来扩展/修改MessageBox类,使你可以传入自定义组件在MessageBox中显示。
/**
 * Simple hack of MessageBox to allow the user to pass in some custom components (such as a form) that will be added to
 * the body of the MessageBox.
 * 
 * Keep in mind:
 * 
 * - You must create each component using Ext.create() before passing it in, rather than using an xtype
 * - MessageBox uses an Anchor layout for its body, so use Anchor layout syntax with your components
 * - Use bodyStyle: {background: 'none'} to get rid of a clashing background issue
 */
Ext.define('My.CustomMessageBox', {
    extend: 'Ext.window.MessageBox',
    /**
     * @cfg customItems An array of user-created components to add to the body of the MessageBox
     */
    customItems: [],
    initComponent: function() {
        var me = this;

        me.callParent();

        me.promptContainer.add(me.customItems);
    }
});

创建自己的自定义窗口也是完全有效的,但是......要使它的外观和行为与MessageBox完全相同,这是一个相当大的麻烦。使用此方法可以以最小的努力保持相同的外观和感觉。
这种方法的缺点是有点像黑客技术,它使用了一个不是公共API的属性(promptContainer),因此可随时被Sencha更改。然而,与要么让您的自定义窗口的外观和行为与MessageBox完全相同(其外观和行为也可能在未来被Sencha更改)或者为应用程序中的每个对话框滚动自己的窗口系统相比,我不介意。

0

这非常简单!

var msgbox = Ext.create('Ext.window.MessageBox',{});
var component = this.myReferences().comp;
msgbox.add(component);
msgbox.show();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接