ExtJS Ext.panel.Panel工具命令

时间:2014-10-13 17:00:12

标签: javascript extjs extjs4

我有这个小组。它按此顺序显示工具图标:齿轮,关闭,折叠。 我想得到的图标是这个顺序:齿轮,折叠,关闭。我无法弄明白。 当我把collapseFirst:true时,崩溃就在第一个位置。

这是SenchFiddle

的替代链接



Ext.application({
    name : 'Fiddle',

    launch : function() {
        Ext.create('Ext.panel.Panel', {
            width : 500,
            height: 200,
            title : 'Panel',
            renderTo: Ext.getBody(),
            closable : true,
            collapsible : true,
            collapseFirst : false,
            tools: [{
                type : 'gear'
            }],
            initTools: function() {
                var me = this,
                    tools = me.tools,
                    i, tool;
    
                me.tools = [];
                for (i = tools && tools.length; i; ) {
                    --i;
                    me.tools[i] = tool = tools[i];
                    tool.toolOwner = me;
                }
    
                // Add a collapse tool unless configured to not show a collapse tool
                // or to not even show a header.
                if (me.collapsible && !(me.hideCollapseTool || me.header === false || me.preventHeader)) {
                    if (Ext.getVersion().major == '4') {
                        me.collapseDirection = me.collapseDirection || me.headerPosition ||     'top';
                        me.collapseTool = me.expandTool = Ext.widget({
                            xtype: 'tool',
                            handler: me.toggleCollapse,
                            scope: me
                        });
    
                        me.updateCollapseTool();
                        // Prepend collapse tool is configured to do so.
                        if (me.collapseFirst) {
                            me.tools.unshift(me.collapseTool);
                        }
                    } else {
                        me.updateCollapseTool();
                        // Prepend collapse tool is configured to do so.
                        if (me.collapseFirst) {
                            me.tools.unshift(me.collapseTool);
                        }
                    }
                }
    
                if (me.pinnable) {
                    me.initPinnable();
                }
    
                // Add subclass-specific tools.
                me.addTools();
                // Append collapse tool if needed.
                if (me.collapseTool && !me.collapseFirst) {
                    me.addTool(me.collapseTool);
                }
                // Make Panel closable.
                if (me.closable) {
                    me.addClsWithUI('closable');
                    me.addTool({
                        xtype : 'tool',
                        type: 'close',
                        scope: me,
                        handler: me.close
                    });
                }
            }
    	});
    }
});

<link href="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/resources/css/ext-all-neptune.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/4.2.1/ext-all-debug.js"></script>
&#13;
&#13;
&#13;

感谢任何人的帮助:)

1 个答案:

答案 0 :(得分:2)

编辑:发现重写initTools方法是更好的解决方案

编辑2:支持ExtJS 4.2和ExtJS 5.x

Ext.create('Ext.panel.Panel', {
        width : 500,
        height: 500,
        title : 'Panel',
        renderTo: Ext.getBody(),
        closable : true,
        collapsible : true,
        collapseFirst : false,
        tools: [{
            type : 'gear'
        }],
        initTools: function() {
            var me = this,
                tools = me.tools,
                i, tool;

            me.tools = [];
            for (i = tools && tools.length; i; ) {
                --i;
                me.tools[i] = tool = tools[i];
                tool.toolOwner = me;
            }

            // Add a collapse tool unless configured to not show a collapse tool
            // or to not even show a header.
            if (me.collapsible && !(me.hideCollapseTool || me.header === false || me.preventHeader)) {
                if (Ext.getVersion().major == '4') {
                    me.collapseDirection = me.collapseDirection || me.headerPosition ||     'top';
                    me.collapseTool = me.expandTool = Ext.widget({
                        xtype: 'tool',
                        handler: me.toggleCollapse,
                        scope: me
                    });

                    me.updateCollapseTool();
                    // Prepend collapse tool is configured to do so.
                    if (me.collapseFirst) {
                        me.tools.unshift(me.collapseTool);
                    }
                } else {
                    me.updateCollapseTool();
                    // Prepend collapse tool is configured to do so.
                    if (me.collapseFirst) {
                        me.tools.unshift(me.collapseTool);
                    }
                }
            }

            if (me.pinnable) {
                me.initPinnable();
            }

            // Add subclass-specific tools.
            me.addTools();
            // Append collapse tool if needed.
            if (me.collapseTool && !me.collapseFirst) {
                me.addTool(me.collapseTool);
            }
            // Make Panel closable.
            if (me.closable) {
                me.addClsWithUI('closable');
                me.addTool({
                    xtype : 'tool',
                    type: 'close',
                    scope: me,
                    handler: me.close
                });
            }

        }
    });