问题描述
在extjs自己带的例子里是桌面图标对应的关联是一级菜单事件。MyDesktop.GridWindow = Ext.extend(Ext.app.Module, { id:'grid-win', //这里定义了ID,到desktop.html可以关联 init : function(){ this.launcher = { text: 'Grid Window', iconCls:'icon-grid', handler : this.createWindow, scope: this } }, createWindow : function(){ var desktop = this.app.getDesktop(); var win = desktop.getWindow('grid-win'); if(!win){ win = desktop.createWindow({ id: 'grid-win', title:'Grid Window', width:740, height:480, iconCls: 'icon-grid', shim:false, animCollapse:false, constrainHeader:true, layout: 'fit', items: new Ext.grid.GridPanel({ 省略。。。。。 }) win.show(); }});对应的desktop.html中<div id="x-desktop"> <dl id="x-shortcuts"> <dt id="grid-win-shortcut"> <a href="#"><img src="images/s.gif" /> <div>Grid Window</div></a> </dt> <dt id="acc-win-shortcut"> <a href="#"><img src="images/s.gif" /> <div>Accordion Window</div></a> </dt> </dl></div>以上没有问题问题如下:但现在做了二级菜单:var windowIndex = 0;MyDesktop.BogusModule = Ext.extend(Ext.app.Module, { init : function(){ this.launcher = { text: 'Window '+(++windowIndex), iconCls:'bogus', handler : this.createWindow, scope: this, windowId:windowIndex } }, createWindow : 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:640, height:480, html : '<p>Something useful would be in here.</p>', iconCls: 'bogus', shim:false, animCollapse:false, constrainHeader:true }); } win.show(); }}); MyDesktop.CollegeMenuModule = Ext.extend(MyDesktop.BogusModule, { init : function(){this.launcher = { iconCls: 'x-icon-waiting',scope: this, shortcutIconCls: 'demo-bogus-shortcut',text: ' 构建111',handler: function() {return false;}, menu: { items:[{ text: 'GOOGLE库'+(++windowIndex), iconCls:'bogus', handler : this.createWindow, scope: this, windowId: windowIndex },{ text: 'WEB库 '+(++windowIndex), iconCls:'bogus', handler : this.createWindow, scope: this, windowId: windowIndex },{ text: '测试库 '+(++windowIndex), iconCls:'bogus', handler : this.createWindow, scope: this, windowId: windowIndex } ]}}}}); 这样的话在 desktop.html中该怎么写啊?ID这个怎么写,请教。想关联到 'WEB库 ' <div id="x-desktop"> <dl id="x-shortcuts"> <dt id="这个怎么写??"> <a href="#"><img src="images/deskbigicon/webtab.gif" width="60" height="60"/> <div>WEB库 1234</div></a> </dt> <dt id="这个怎么写??" > <a href="#"><img src="images/deskbigicon/ create_tab.gif" width="60" height="60" /> <div>测试库构建</div></a> </dt> </dl>初学,不太会用。不明白这里子menu的id怎么给,写什么??请教好心人解答。谢谢 问题补充:lizhi92574 写道
解决方案
menu 不能给的。dt id 对应 MyDesktop.BogusMenuModule 的id。在执行createWindow的函数可能会出现问题。你可以参考 Ext.Desktop shortcuts 事件代码 及 Ext.app.App.getModule() 函数,可对其修改达到你的要求