operamasks-ui tree grid

  <script type="text/javascript">
        $(document).ready(function() {
       
       
       
       
       
        var col,
        lan =window.navigator.language;
        //首先从服务器端获取表头数据,再初始化数据表
        $.getJSON("griddata.do?method=coldata&language="+lan,function(data){
        col = data;
       
       
       
       
                var newDiv =  "<input name='id' style='display: none'/> <table>  "

                var callenth = col.length;
               
               
                for(var i = 1;i<callenth;i++){
               
                newDiv = newDiv     + "    <tr>"
                 + "       <td>"+col[i].header+":</td>"
                + "      <td><input name='"+col[i].name+"' /></td>"
                + "   </tr>"
               
               
                }
               
               
                newDiv = newDiv    + "   </table>";
               
               
              document.getElementById("dyform").insertAdjacentHTML("beforeEnd", newDiv);   
       
       
       
        $("#grid").omGrid({
            dataSource: "../../../gridcrud.do",
            width : 686,
                     height : 332,
                     limit : 10,
                     colModel : data
            });
        });
       
       
       




            $("#mytree").omTree({
                dataSource : "../../omTree.json?method=simpleModel",
                simpleDataModel: true,
          
                onBeforeExpand : function(node){
                var nodeDom = $("#"+node.nid);
                if(nodeDom.hasClass("hasChildren")){
                nodeDom.removeClass("hasChildren");
                $.ajax({
                            url: '../../omTree.json?content=children',
                            method: 'POST',
                            dataType: 'json',
                            success: function(data){
                           
                           
                                var  datanew = node.children;      
                                var lg = 0;
                                if(datanew!=null){
                                var lg = datanew.length;        
                                }                                 
                               for(i = 0;i<lg;i++){               
                                $("#mytree").omTree("remove",datanew[0],node);         
                                }
                         
                        //     if(lg>0&&data.length>0) { 
                         //     $("#mytree").omTree("newisToFolder",node,true);   
                         //     }.
                        
                        
                         /*   注掉子删除完后的样式   1060 行左右
                        
                               if(pNode&&pNode.nid&&data.length < 1){
                               //  self._changeToFolderOrFile(pNode,false);
                                 }
                        
                         */
                             
                             //   node.expanded = true;
                                $("#mytree").omTree("insert", data, node);
                            }
                        });
                }
                return true;
                },
           
           
            onClick : function(){
            $("#menu").omMenu("hide");
            },
         
       
       
            onRightClick : function(nodedata, e){
            //通过节点的text属性来判断是否响应右键菜单,也可以自行添加特殊属性来判断
            if($.inArray(nodedata.text, array1)===-1){
            //右键选中并显示菜单
            $("#mytree").omTree("select", nodedata);
            $("#menu").omMenu("enableItem", "002");
                  $('#menu').omMenu('show',e);
                  if($.inArray(nodedata.text, array2)!=-1){
                  $("#menu").omMenu("disableItem", "002");
                  }
            }
            e.preventDefault();
            }
        });
        //左键点击页面隐藏菜单
        $("body").bind("click", function(){
        $("#menu").omMenu("hide");
        });
        var addCount = 1;
        $('#menu').omMenu({
        contextMenu : true,
            dataSource : [{id:'001',label:'增加节点freshfathar',icon:'../../example/tree/images/add.png'},
                          {id:'002',label:'collapse',icon:'../../example/tree/images/delete.png'},
                          {id:'003',label:'expand',icon:'../../example/tree/images/check.png'},
                          {id:'004',label:'refresh',icon:'../../example/tree/images/uncheck.png'},
                          {id:'005',label:'恢复默认',icon:'../../example/tree/images/refresh.png'}
                         ],
            onSelect : function(item){
            var node = $("#mytree").omTree("getSelected");
           
           
            $("#menu").omMenu("hide");
            if(item.id=="001"){
          
          
            node =  $("#mytree").omTree("getParent",node);
              if(node!=null){
           
            collapse(node);
            getdata(node);
            expand(node);
           
              }
           
           
            }else if(item.id === "002"){
            collapse(node);
            }else if(item.id === "003"){
            expand(node);
            }else if(item.id === "004"){
           
            //只有展开状态的 才能刷新  有小孩 就是展开
            var  datanew = node.children;      
           
              if(datanew!=null){
              collapse(node);
                  getdata(node);

                  expand(node);
             
                          }
             
             
           
           
           
            }else if(item.id === "005"){
           
            }
            }
       
       
           
           
            });
       
       
       
       

           
           
           
        });
       

       
       
        function collapse(node) {
           
            $("#mytree").omTree("collapse", node);
        }
       

        function expand(node) {
            $("#mytree").omTree("expand", node);
        }
       
       
       
        function getdata(node) {
       
       
$.ajax({
            url: '../../omTree.json?content=children',
            method: 'POST',
            async:false,
           
            dataType: 'json',
            success: function(data){
           
                var  datanew = node.children;      
                var lg = 0;
                if(datanew!=null){
                var lg = datanew.length;        
                }
               
               
               for(i = 0;i<lg;i++){               
                $("#mytree").omTree("remove",datanew[0],node);         
                }
              
         //      if(data.length>0) {
           //  $("#mytree").omTree("newisToFolder",node,true);   
           //   }
              
                $("#mytree").omTree("insert", data, node);
            }
        });
       
        }
       



你可能感兴趣的:(operamasks-ui tree grid)