jQuery treetable第二次加载的数据为什么展不开啊?

2025-05-13 14:48:32
推荐回答(1个)
回答1:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage>" %>






    

    

    

    
    
     

         $(document).ready(function() {
             $("#dnd-example").treeTable();

             // Drag & Drop Example Code
             $("#dnd-example .file, #dnd-example .folder").draggable({
                 helper: "clone",
                 opacity: .75,
                 refreshPositions: true, // Performance?
                 revert: "invalid",
                 revertDuration: 300,
                 scroll: true
             });

             $("#dnd-example .folder").each(function() {
                 $($(this).parents("tr")[0]).droppable({
                     accept: ".file, .folder",
                     drop: function(e, ui) {
                         $($(ui.draggable).parents("tr")[0]).appendBranchTo(this);
                     },
                     hoverClass: "accept",
                     over: function(e, ui) {
                         if (this.id != ui.draggable.parents("tr.parent")[0].id && !$(this).is(".expanded")) {
                             $(this).expand();
                         }
                     }
                 });
             });

             // Make visible that a row is clicked
             $("table#dnd-example tbody tr").mousedown(function() {
                 $("tr.selected").removeClass("selected"); // Deselect currently selected rows
                 $(this).addClass("selected");
             });

             // Make sure row is selected when span is clicked
             $("table#dnd-example tbody tr span").mousedown(function() {
                 $($(this).parents("tr")[0]).trigger("mousedown");
             });
         });
  
  
  
<%Html.BeginForm("SearchProduct","ProductCategory",FormMethod.Post); %>
    
        
            
                搜索
            
        
        
            
                搜索条件:
            
            
             分类代码:<%=Html.TextBox("categoryCode")%>
             分类名:<%=Html.TextBox ("categoryName") %>
            
            
            
        
    
<%Html.EndForm(); %>
    
    
        
            
                产品类型列表
            
            
                 <%= Html.ActionLink("添加一级分类", "Add",null,new {@class="addLink"}) %>
            
        
    

    
            
                商品分类代码
                商品分类名
                序号
                操作
            
        
        <%
            
            foreach (var item in Model) 
           {
               var node = "node--";
               var parent = "parent ";
               var bar = "-";
               var childOf = "child-of-";
                
               var parentIdName = node + item.Code;
               var parentClassName = parent;
                
               var childIdName = "";
               var childClassName = "";

              // var noParentIdName = childIdName;
               var noChildClassName = "";
               
               string[] productCategoryParent=null;
               if(item.Parent ==null)
                {
                    productCategoryParent=item.Code.Split (',');
                    
                }
               foreach (var pcp in productCategoryParent)
                {
                    
                }
               //一级分类:无父类
               if (item.Parent == null)
               { %> 
                
                    "  class="<%=parentClassName %>">
                        
                            <%= Html.Encode(item.Code)%>
                        
                        
                            <%= Html.Encode(item.Name)%>
                        
                         
                            <%= Html.Encode(item.Sequence)%>
                        
                        
                        
                            <%= Html.ActionLink("编辑", "Edit", new { CategoryId = item.ID }, new { @class = "editLink" })%> |
                            <%= Html.ActionLink("删除", "Delete", new { CategoryId = item.ID }, new { @class = "delLink" })%> |
                            <%= Html.ActionLink("添加子类", "AddChild", new { CategoryId = item.ID }, new { @class = "addLink" })%>
                        
                    
                
                
            <%}
                  //有父级分类且有子类
               if (item.Parent != null && item.Children != null) 
               {
                   childIdName = node + item.Parent .Code +bar+ item.Code;
                   childClassName = parent + childOf + node + item.Parent .Code;
                  %>
                   
                        "  class="<%=childClassName%>">
                            
                                <%= Html.Encode(item.Code)%>
                                
                            
                            
                                <%= Html.Encode(item.Name )%>
                            
                             
                                <%= Html.Encode(item.Sequence)%>
                            
                            
                                <%= Html.ActionLink("编辑", "Edit", new { CategoryId = item.ID }, new { @class = "editLink" })%> |
                                <%= Html.ActionLink("删除", "Delete", new { CategoryId = item.ID }, new { @class = "delLink" })%> |
                                <%= Html.ActionLink("添加子类", "AddChild", new { CategoryId = item.ID }, new { @class = "addLink" })%>
                            
                        
                   
               <%}
               //有父级分类且无子类
                if(item.Parent!=null && item.Children ==null)
                {
                    childIdName = node + item.Parent.Code +bar+ item.Code;
                    noChildClassName = childOf + node + item.Parent .Code;
                    %>
                     
                        "  class="<%=noChildClassName%>">
                            
                                <%= Html.Encode(item.Code)%>
                              
                            
                            
                                <%= Html.Encode(item.Name )%>
                            
                             
                                <%= Html.Encode(item.Sequence)%>
                            
                            
                                <%= Html.ActionLink("编辑", "Edit", new { CategoryId = item.ID }, new { @class = "editLink" })%> |
                                <%= Html.ActionLink("删除", "Delete", new { CategoryId = item.ID }, new { @class = "delLink" })%> |
                                <%= Html.ActionLink("添加子类", "AddChild", new { CategoryId = item.ID }, new { @class = "addLink" })%>
                            
                        
                   
                 <%} 

           } %>