各位,我的extjs页面有个树形菜单,请问能不能利用for循环动态地帮子节点加上click响应函数??

解决方案 »

  1.   

    直接监听它的click事件啊listeners:{
    click:function(node,event){
    event.stopEvent();//阻止默认的事件
    if(node.isLeaf()){
     //叶子节点事件处理
    }else{
    node.toggle();
    }
    }
    }
      

  2.   

    添加完成后,重新绑定它的click事件嘛
      

  3.   

    请教一下如何重新绑定??麻烦能不能说得具体点??
    比如root是根节点,是否用for循环遍历node.childNodes[i]??
      

  4.   

    请教一下如何重新绑定??麻烦能不能说得具体点??
    比如root是根节点,是否用for循环遍历root.childNodes[i]??(上面打错)
      

  5.   

    添加的是Node node吧?
    node.on("click",function(){
    //do something here
    });
      

  6.   

    已经解决了,把代码贴出来共享一下:
    for(var j=0;j<root.data.items.length;j++)
    {
        var wz=new Ext.tree.TreeNode({
        text:storeNews.getAt(j).get('title'),
        listeners:{
            "click":function(node,event){
                  event.stopEvent();
                  //alert(node.text);
                  addNewsTab(node.text,node.attributes.author,
                             node.attributes.date,node.attributes.neirong);
    }
         }
         });     //动态子节点和响应函数addNewsTab()所需要的参数
         wz.attributes={ author:storeNews.getAt(j).get('author'),
                            date:storeNews.getAt(j).get('date'),
                            neirong:storeNews.getAt(j).get('neirong')};
         root.appendChild(wz);
    }