最近在用ExtJS做系统,准备在ExtJS desktop的基础上进行改造,由于官方例子只有一级菜单,对于二级菜单的调用就没有办法了,所以想要在桌面上点击快捷方式图标也能打开窗口的话就需要另想办法了.
查看完源代码后,发现也并不是很难,想要达到目的只需要修改 ExtJS desktop 自带例子的两个js文件即可,贴上代码,欢迎指正:
App.js
- getModule : function(name){
- var ms = this.modules;
- for(var i = 0, len = ms.length; i < len; i++){
- if(ms[i].id == name || ms[i].appType == name){
- return ms[i];
- }
- else
- {
- if(Ext.isDefined(ms[i].launcher.menu) == true && ms[i].launcher.menu.items.length > 0)
- {
- for(var j = 0, lens = ms[i].launcher.menu.items.length; j < lens ; j++)
- {
- if(ms[i].launcher.menu.items[j].id == name)
- {
- return ms[i].launcher.menu.items[j];
- }
- }
- }
- }
- }
- return '';
- }
desktop.js
- if(shortcuts){
- shortcuts.on('click', function(e, t){
- if(t = e.getTarget('dt', shortcuts)){
- e.stopEvent();
- var module = app.getModule(t.id.replace('-shortcut', ''));
- if(module){
- if(Ext.isDefined(module.itemId) == false)
- {
- module.createWindow();
- }
- else
- {
- var str = t.id.replace('-shortcut', '');
- var strLeft = str.substring(0,str.indexOf("-"));
- var strRight = str.substring(str.indexOf("-")+1);
- var strLefts = strLeft.substring(0,1).toUpperCase()+strLeft.substring(1);
- var strRights = strRight.substring(0,1).toUpperCase()+strRight.substring(1);
- var fun = "create".concat(strLefts).concat(strRights).concat("Window()");
- eval("module.scope."+ fun);
- }
- }
- }
- });
- }
[比如的 menu id 为 menu-query, 那么创建窗口的方法为createMenuQueryWindow, 这样就没问题了]
此外在页面端的js文件中menu中需配置 itemId 属性