2 qq 21392937 qq_21392937 于 2015.07.21 17:00 提问

extjs如何控制左侧菜单默认不打开,现在项目进去后默认打开第一个,下面是我的js代码 1C
 Ext.namespace('Ext.app.frame');
Ext.app.frame.LeftPanel = Ext.extend(Ext.Panel, {
    //初始化加载的菜单ID
    welcomeMenuId : customInfo['defaultTopMenuId'],
    //项目路径
    context : customInfo['context'],
    //构造方法
    constructor : function(_cfg) {
        Ext.apply(this, _cfg);
    },
    wizCount :0,
    readyCount :0,
    //初始化
    initialize:function(_cfg){
        //生成左侧面板
        Ext.app.frame.LeftPanel.superclass.constructor.call(this, {
            id : 'accordion-panel',
            iconCls : 'icon-nav',
            layout : 'accordion',
            region : 'west',
            margins : '10 10 2 2',
            width : 220,
            bodyStyle : 'background-color:#DFE8F6',
            collapsible : true,
            split : false,
            layoutConfig : {
                animate : true
            }
        });
        //左侧面板首次设置内容
        var welcomeMenu = {menuId:this.welcomeMenuId, text:customInfo['defaultTopMenuName']};
        this.setContent(welcomeMenu);
    },
    //设置面板内容(主要方法)
    setContent:function(currMenu){
        var aim = Ext.getCmp('accordion-panel');
        var currScope = this;
        aim.removeAll(true);
        if(currMenu!=undefined && currMenu.menuId!=undefined){
            var _temptitle = currMenu.text || "";
            aim.setTitle(_temptitle);
            //添加扩展,如果菜单配置URL为IFM:开头的话, 表示为做菜单是扩展的菜单,嵌入IFRAME显示URL
            var _tempURL = currMenu.menuURL|| "";
            if(_tempURL!=""){
                aim.body.update("");
            }
            if(_tempURL.indexOf("IFM:")>-1){
                _tempURL = _tempURL.substring(4);
                aim.body.update("<IFRAME width=\"100%\" height=\"100%\" FRAMEBORDER=0 SCROLLING=auto SRC='"+_tempURL+"'></IFRAME>");
                if(currScope.ownerCt.menuBar){
                    currScope.ownerCt.menuBar.enableAllButtons();
                }
                return;
            }
            var requesturl = this.context+'/menu!topLeft.lxd?menuId='+currMenu.menuId;
            Ext.Ajax.request({
                url: requesturl,
                success: function(response) {
                    //获取响应的json字符
                    json = Ext.decode(response.responseText);
                    if(json!=undefined && json.length!=undefined){
                        currScope.wizCount = json.length;
                        currScope.readyCount = 0;
                        for(var i=0;i<json.length;i++){
                            var left = json[i];
                            var title = left.text;
                            var id = left.id;
                            var url;
                            if(left.menuUrl!=undefined){
                                url=left.menuUrl.substring(0,4)=="IFM:"?left.menuUrl.substring(4):left.menuUrl;
                            }
                            var target = left.urltarget;
                            var panel;
                            if(url && target=="leftFrame"){
                                if(url.substring(0,4)!="http"){
                                    url = customInfo['context']+"/"+url;
                                }
                                panel = new Ext.Panel({
                                    id : id,
                                    title : title,
                                    layout: 'fit',
                                    border: false,
                                    iconCls : 'icon-nav',
                                    items : [
                                        new Ext.ux.IFrameComponent({
                                            id: 'menu_iframe_'+id,
                                            url: url
                                        })
                                    ]
                                });
                            }else{
                                panel = new Ext.app.frame.WizardPanel({
                                    id : id,
                                    title : title,
                                    group : 'group',
                                    checked : 'checked',
                                    dataUrl : '/menu!downLeft.lxd?menuId=' + id
                                });
                            }
                            aim.add(panel);
                            aim.doLayout();
                            currScope.readyCount++;
                            if(currScope.readyCount == currScope.wizCount){
                                if(currScope.ownerCt.menuBar){
                                    currScope.ownerCt.menuBar.enableAllButtons();
                                }
                            }
                        }
                    }else{
                        Ext.Msg.alert('错误','读取菜单错误!');
                        if(currScope.ownerCt.menuBar){
                            currScope.ownerCt.menuBar.enableAllButtons();
                        }
                    }
                },
                failure: function(){
                    Ext.Msg.alert('错误','连接服务器超时!');
                    if(currScope.ownerCt.menuBar){
                        currScope.ownerCt.menuBar.enableAllButtons();
                    }
                }
            });
        }
    }

});
Ext.app.frame.WizardPanel = Ext.extend(Ext.Panel, {
    context : customInfo['context'],
    iconCls : 'icon-nav',
    border : false,
    rootVisible : false,
    autoScroll : true,
    dataUrl : null,
    //buttons : {},
    tree : null,
    constructor : function(_cfg) {
        Ext.apply(this, _cfg);
        var _tree = new Ext.tree.TreePanel({
                    iconCls : 'icon-nav',
                    border : false,
                    rootVisible : false,
                    loader : new Ext.tree.TreeLoader({
                                // dataUrl : context +
                                // '/jsonTree!wizardJson.lxd'
                                dataUrl : this.context + this.dataUrl
                            }),

                    style : {
                        padding : 3
                    },
                    root : new Ext.tree.AsyncTreeNode({
                        text : _cfg.title || this.title,
                            // ,
                            // children : _cfg.childrens || null
                         expanded : false

                        }),
                    listeners : {
                        'click' : function(n) {
                            try {
                                if (n.leaf) {
                                    if(n.attributes.urltarget=='_blank'){
                                        var openURL = n.attributes.menuUrl;
                                        if(openURL.substring(0,4)!="http"){
                                            openURL = customInfo['context']+"/"+openURL;
                                        }
                                        window.open(openURL);
                                    }else{
                                        this.onNodeClick(n.id, n.text,n.attributes.menuUrl);
                                    }
                                }else{
                                    if(n.attributes.menuUrl){
                                        if(n.attributes.urltarget=='_blank'){
                                            var openURL = n.attributes.menuUrl;
                                            if(openURL.substring(0,4)!="http"){
                                                openURL = encodeURI(customInfo['context']+"/"+openURL);
                                            }
                                            window.open(openURL);
                                        }else{
                                            this.onNodeClick(n.id, n.text,n.attributes.menuUrl);
                                        }
                                    }
                                }
                            } catch (e) {
                            }
                        },
                        scope : this
                    }

                });


            this.tree = _tree;


            Ext.app.frame.WizardPanel.superclass.constructor.call(this, {
                        margins : '2 0 5 5',
                        layout : 'anchor',
                        items : [this.tree]

                    });

    },
    afterRender : function(){
        Ext.app.frame.WizardPanel.superclass.afterRender.call(this);
    },
    // 树图刷新
    tree_refresh : function(menuId) {
        this.refresh(menuId);
    },
    ReturnValue : function(title, value) {
        Ext.Msg.show({
                    title : title,
                    msg : value,
                    icon : Ext.Msg.INFO,
                    minWidth : 210,
                    buttons : Ext.Msg.OK
                });
    },
    // 为叶子菜单增加对应点击事件,调用链接对应的页面
    onNodeClick : function(id,name,menuUrl) {

        var tabPanel = Ext.getCmp("content-panel");
        var allItems = tabPanel.items.items;
        var tabPage;
        var b = true;
        var delegateArray = {'id':id,'name':name,'menuUrl':menuUrl};
        if(menuUrl.substring(0,4)!="http"){
            menuUrl = encodeURI(customInfo['context']+"/"+menuUrl);
        }
        for (var i = 0; i < allItems.length; i++) {
            var _text = allItems[i].title;
            if (_text == name) {
                tabPage = allItems[i];
                // 设置当前tab页
                tabPanel.setActiveTab(tabPage); 
                b = false;
                // 重新刷新当前活动tab
                Ext.get('f_'+name).dom.src=menuUrl;
                break;
            }
        }
        if (b) {        
            Ext.Ajax.request({
                url : menuUrl,// 增加传递参数,处理暂停流程
                success : this.showNodeTabPanel.createDelegate(this, delegateArray, true),// 调用异步函数,传递对应参数
                failure : this.menuError,
                scope : this
            });
        }
    },
    // 为叶子菜单增加对应点击事件,调用链接对应的页面
    showNodeTabPanel : function(result, thisObj, delegateArray) {
        var text = result.responseText;
        var tabPanel = Ext.getCmp("content-panel");
        var _url = delegateArray['menuUrl'];
        if(_url.substring(0,4)!="http"){
            _url = encodeURI(customInfo['context']+"/"+_url);
        }
        tabPage = tabPanel.add({
            title : delegateArray['name'],
            html : "<iframe id='f_" + delegateArray['name'] + "' scrolling='auto' frameborder='0' width='100%' height='100%' src='"
                    + _url + "'></iframe>",
            closable : true
        });
        tabPanel.setActiveTab(tabPage); // 设置当前tab页
    },
    refresh : function(topMenuId) {
        var loader = new Ext.tree.TreeLoader({
                    dataUrl : this.context + '/menu!left.lxd?menuId=' +topMenuId
                });
        loader.load(this.tree.root);
        this.tree.root.expand(true);//不起作用?
    },
    expandTreeNodes: function(){
        var tree = this.tree;
        tree.root.expand(true);
    }
});


//根据组件ID获得相应的组件
function getComponent(id){
    return  Ext.getCmp(id);
}

//tab数量大于6个时,显示的提示信息
function alarmMessage(){
    Ext.Msg.alert("提示信息","最多打开6个tab,请关闭无用页面");
}

2个回答

caozhy
caozhy   Ds   Rxr 2015.07.21 19:43
qq_21392937
qq_21392937 请帮忙看看,我加的代码是否正确,谢谢了
2 年多之前 回复
qq_21392937
qq_21392937   2015.07.21 20:58

我在代码中加上(collapased:true)后还是不行,还是会打开第一个,在下面代码加的:

initialize:function(_cfg){
    //生成左侧面板
    Ext.app.frame.LeftPanel.superclass.constructor.call(this, {
        id : 'accordion-panel',
        iconCls : 'icon-nav',
        layout : 'accordion',
        region : 'west',
        margins : '10 10 2 2',
        width : 220,
        bodyStyle : 'background-color:#DFE8F6',
        collapsible : true,
            **  collapased:true,**
        split : false,
        layoutConfig : {
            animate : true
        }
    });
Csdn user default icon
上传中...
上传图片
插入图片