2011-06-09 52 views

回答

1

我认为这将工作:

var contextMap = {} 
dojo.provide('menu'); 
dojo.declare('menu', [dijit.Menu] , { 
bindDomNode : function(a,b,c){ 
this.inherited(arguments); 
contextMap[a] = this; 
console.log(contextMap) 
} 
}) 

更新的解决方案通过powtac:
这个作品!我在菜单实例化之前运行它。诀窍是使用same superClass as className,在这种情况下'dijit.Menu'为字符串。

dojo.ready(function() { 
    dojo.declare('dijit.Menu', [dijit.Menu], { 
     bindDomNode: function(a,b,c) { 
      this.inherited(arguments); 
      console.log(a); 
     }, 
    }) 
}) 

// ... 
menu = new dijit.Menu(...); // when called the the event is caught 
           // and runs into the console.log(a); 
+0

菜单添加到DOM后,我可以运行它吗? – powtac 2011-06-11 12:52:05

+0

似乎不工作。 :(contextMap是空的 – powtac 2011-06-21 13:10:38

+0

找到了一个解决方案!谢谢你rajkamal!我用我改编的代码更新了你的答案...... – powtac 2011-06-21 13:30:30

0

为什么看通过DOM寻找的东西,有连接时,你可以只是看在所有的dijit.Menu部件的东西呢?

您还可以轻松地扩展dijit.Menu小部件并添加自定义信号作为窗口小部件创建过程的一部分。

+0

我怎么能这样做? – powtac 2011-06-10 11:55:37