如何在Ext JS的弹出窗口中显示Ext.FormPanel?

Edw*_*uay 3 javascript extjs popup

我可以在Ext JS中创建一个"确认框",如下所示:

在此输入图像描述

使用此代码:

...
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
        });
    },
 ...
Run Code Online (Sandbox Code Playgroud)

我怎样才能创建一个像这样的带有灰色背景的弹出式背景,而不是MessageBox,它有一个Ext.FormPanel?,例如,如何将此代码放入带有暗灰色背景的弹出窗口中?

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'
            }]
    });
Run Code Online (Sandbox Code Playgroud)

bri*_*ngr 9

您可以使用窗口执行此操作,因为MessageBox没有任何配置来添加面板.

要显示掩码,只需将config选项模式设置为true即可.

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


小智 5

我找到了一种非常简单的方法来扩展/破解 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);
    }
});
Run Code Online (Sandbox Code Playgroud)

创建您自己的自定义 Window 也是完全有效的,但是......让它看起来和行为与 MessageBox 完全相同是一个非常重要的麻烦。此方法以最少的努力保持相同的外观和感觉。

这有一个缺点,即使用不属于公共 API 的属性 (promptContainer) 有点像 hack。所以这可能会被 Sencha 随时更改。然而,与让您的自定义 Window 看起来和行为完全像 MessageBox 的替代方案相比(Sencha 将来也可以更改其外观和行为),或者为您的每个对话框滚动您自己的 Windows 系统。应用程序,我不介意。