extjs 기술 의 tree 기술 분석 사건 트리거

3556 단어 JavaScriptjsonjspext
<script type="text/javascript">
var Tree = Ext.tree;
var tree = null;
Ext.onReady(function(){
    tree = new Tree.TreePanel({
        el:'tree-div',
        onlyLeafCheckable:false,
        rootVisible: true,
        autoScroll:true,
        animate:false,//    
        enableDD:true,//       
        containerScroll:true,
        lines:true, 
        checkModel:'cascade',
        loader:new Tree.TreeLoader({dataUrl:"json.jsp",
                       baseAttrs: {uiProvider: Ext.tree.TreeCheckNodeUI}
        })
      });
        
    // set the root node
    var root = new Tree.AsyncTreeNode({
        text: '      ',
        id:'root'
    });


    //        
     tree.on('append', function(tree, node){ 
       //if(node.id == 'foo'){
      //  alert("append");
       // } 
     });

    //        
     tree.getSelectionModel().on('selectionchange', function(sm, node){ 
          // alert("selectionchange");
     });

    //        
    tree.on('click', function(node){
        if(node.id!='root'){
            alert(node.id);
            alert(node.text);
        }
    });

    //          
    tree.on('beforeload',function(node){   
        if(node.id!='root'){
             // alert("beforeload");;
          }
    }); 

    //          
    tree.on('contextmenu',function(node,event){  
         // alert("node.id="+ node.id);
          event.preventDefault(); //      
          rightClick.showAt(event.getXY());//        ,    
         }); 

    //        ,            ,                ,             ,               TREE   
    function handleMoveNode(tree, node, oldParent, newParent, index) { 
        alert("      ");
        alert("node.attributes.id = " + node.attributes.id +"
" + "node.parentNode.attributes.id = " + node.parentNode.attributes.id ) alert("newParent.attributes.id = " + newParent.attributes.id); alert("oldParent.attributes.id = " + oldParent.attributes.id); } tree.addListener('movenode', handleMoveNode); tree.addListener('beforemovenode', function(t,node,oldParent,newParent,i) { if(oldParent.id == newParent.id ) { alert("Re-ordering not supported"); return false; } }); // var rightClick = new Ext.menu.Menu({ id :'rightClickCont', items : [{ id:'rMenu1', text : ' 1', // handler:function (){ alert(' !'); } }, { id:'rMenu2', text : ' 2' }, { id:'rMenu3', text : ' 3' }] }); tree.setRootNode(root); // render the tree tree.render(); root.expand(); }); </script>

좋은 웹페이지 즐겨찾기