Extjs4.0 开发笔记-desktop开始菜单动态生成方法

desktop开始菜单动态生成方法:

Desktop.html中,在<scripts>中的Ext.onReady之前添加如下:

              

 var mArr = [];//这里是保存显示模块的数组



        var _menus = [@Html.Raw(ViewBag.Menu as string)]; //从服务端传来的菜单json  



               //遍历json



        for (var i =0; i < _menus.length; i ++){



            var s = Ext.define('MyDesktop.Menu' + i, {



                extend: 'MyDesktop.BogusModule',



                init : function() {



                    this.launcher = {



                        text: _menus[i].menuname,



                        iconCls: 'bogus',



                        handler: function() {



                            return false;



                        },



                        menu: {



                            items: []



                        }



                    };



                    if(_menus[i].menus != null){



                        for (var j = 0; j < _menus[i].menus.length; j++) {



                            this.launcher.menu.items.push({



                                text: _menus[i].menus[j].menuname,



                                iconCls:'bogus',



                                url: _menus[i].menus[j].url,



                                handler : function(src){



                                    var desktop = this.app.getDesktop();



                                    var win = desktop.getWindow('bogus'+src.windowId);



                                    if(!win){



                                        win = desktop.createWindow({



                                            id: 'bogus'+src.windowId,



                                            title:src.text,



                                            width:850,



                                            height:500,



                                            html : '<iframe style="position:relative;background-color:transparent;" allowtransparency="true" width="100%" height="100%"  frameborder="0" src="' + src.url + '"></iframe>',



                                            iconCls: 'bogus',



                                            animCollapse:false,



                                            constrainHeader:true



                                        });



                                    }



                                    win.show();



                                    return win;



                                },



                                scope: this,



                                windowId: i + j



                            });



                        }



                    };                   



                }



            });



            myArr.push(new s);



        };

 

在App.js中getModules : function(){}改为:

           

    GetModules:function(){        



                         mArr.push(new MyDesktop.Notepad());//这个地方也可以增添静态模块



                         return mArr;



               }

你可能感兴趣的:(Extjs4.0)