使用javascript,类似在复选框的onclick事件中增加相应的操作就可以了

解决方案 »

  1.   

    tree.on('checkchange', function(node, checked) {      
            node.expand();      
            node.attributes.checked = checked;      
            node.eachChild(function(child) {      
                child.ui.toggleCheck(checked);      
                child.attributes.checked = checked; 
                child.attributes.onclick = checkbox();
                child.fireEvent('checkchange', child, checked);      
            });  这地方加一个事件试试
      

  2.   

    treeNode 有一个事件方法:
    checkchange ( Node this, Boolean checked );
    Fires when a node with a checkbox's checked property changes,
    然后你照楼上的做就是了。
    我觉得学Ext关键还是自己看文档。http://www.ajaxjs.com/docs/
    毕竟这个东西会的人不多。
    我花了一个月的时间做了一个基于Extjs Ajax的应用。 基本上用到了Extjs得方方面面。 当时对Extjs一无所知, 完全是自己看文当看出来的。
    因为发贴问, 得到得答案都很有限。
      

  3.   


    chinmo兄,能详细一点吗?我查了一上午,也没啥头绪,加了这句: child.attributes.onclick = checkbox(); 
    就可以和剩下两部分产生联系了吗?还是要在别的什么地方实现checkbox()这个方法呢?
      

  4.   

    Ext.onReady(function(){
        // shorthand
        var Tree = Ext.tree;
        
        var tree = new Tree.TreePanel({
            el:'tree-div',
            useArrows:true,
            autoScroll:true,
            animate:true,
            enableDD:true,
            containerScroll: true,        // auto create TreeLoader
            dataUrl: 'get-nodes.php',        root: {
                nodeType: 'async',
                text: 'G:\\',
                draggable:false,
                id:'\\'
            }
        });
            tree.on('checkchange', function(node, checked) {      
            node.expand();      
            node.attributes.checked = checked;      
            node.eachChild(function(child) {      
                child.ui.toggleCheck(checked);      
                child.attributes.checked = checked; 
                child.attributes.onclick = checkbox(); 
                child.fireEvent('checkchange', child, checked);      
            });      
        }, tree);     
        checkbox(){
        alert('被选中了');
        }    // render the tree
        tree.render();
        tree.getRootNode().expand();
    });
    我这样加了,没反应啊...
      

  5.   

    大侠呀,怎样把树上的结点组合成一个带斜线的全路径呢?如:D:\wamp\www\layoutDemo
      

  6.   


    tree.on("check",function(node,checked){
                 alert(checked);
                 var pNode = node.parentNode;
                 while(pNode){
                 alert(pNode.text);
                 pNode = pNode.parentNode;
                 }
    };
    你把这些alert出来的字符串拼接起来就是路径了.
      

  7.   

    给你更详细一点的:            tree.on("check",function(node,checked){
                 var temp = new Array();//临时数组,用来放父节点的text
                 temp[temp.length] = node.text;
                 var pNode = node.parentNode;
                 while(pNode){//如果pNode不为null
                 temp[temp.length] = pNode.text;
                 pNode = pNode.parentNode;//一直向上找,
                 }
                 var path = "";
                 for(var i=temp.length-1; i>=0; i--){//将数组中的各个text倒排, 就是你要的路径.
                 if(i!=temp.length-1){
                 path+="\\";
                 }
                 path+=temp[i];
                 }
                 alert(path);
      

  8.   

    大侠们啊,checkchange 或者 check,都是在树结点的checkbox发生改变时触发,而待选目录的路径可能用户都没有点击,我该如何获得它的路径呢?
      

  9.   

    你从root深度遍历, 得到所有的叶子节点, 这写叶子节点就是你要的所有的节点, 不管用户有没有点机 
    给你一个遍历的例子,虽然是java的, 不过道理都一样。
    变历C:\\WINNT\\system32下的所有文件:(2000系统)import java.io.File;public class DocTree {

    public void drawDocTree(File root,int depth,int childrenSize){
    if (root.isFile()){
    drawFile(root,depth);
    }
    else {
    drawForder(root,depth);
    File[] files = root.listFiles() ;
    if (files!=null && files.length!=0){
    int size = files.length ;
    //print forder(s) first ,then file(s) ;
    for (int i=0 ;i<size ;i++){
    drawDocTree(files[i],depth+1,size);
    }
    }
    }
    }
    /**
     *draw forder
     *@param root: current forder ;
     *@param depth: current depth ; 
     */
    private void drawForder(File root, int depth) {
    for (int i=0 ;i<depth ;i++){
    System.out.print("|   ");
    }
    System.out.print("|---");
    System.out.print("["+root.getName()+"]");
    System.out.println();
    }
    /**
     * @param root
     * @param depth
     */
    private void drawFile(File root, int depth) {
    // TODO Auto-generated method stub
    for (int i=0 ;i<depth ;i++){
    System.out.print("|   ");
    }
    System.out.print("|---");
    System.out.print(root.getName());
    System.out.println();
    }

    public static void main(String[] args){ DocTree docTree = new DocTree();
    File file = new File("C:\\WINNT\\system32") ;
    docTree.drawDocTree(file, 0, 1) ;

    }
    }
      

  10.   

    1.加上下面代码 2.把get-nodes.php中的相应的qtip注释去掉,就可以为树加上提示:Ext.QuickTips.init();
    Ext.apply(Ext.QuickTips.getQuickTip(),{
    //maxWidth: 200,
    //minWidth: 100,
    //showDelay: 50,
    //trackMouse: true,
    //hideDelay: true, 
    //closable: true,
    //autoHide: false,
    //draggable: true,
    dismissDelay: 0
    });