我现在要做TreeTable的延迟加载,请问我怎么获取TreeTable中的动态的列的IDJS代码
// Make sure row is selected when span is clicked
$("table#dnd-example tbody tr span").mousedown(function() {
$($(this).parents("tr")[0]).trigger("mousedown");
var NameOrderBy = "productCategoryId";
LoadCity(NameOrderBy);
});
function LoadCity(NameOrderBy) {
$.ajax({
type: "get",
dataType: "json",
url: "ProductCategories.aspx?Name=" + NameOrderBy,
success: function(msg) {
var data = msg;
$("#EmployeeINfo").html("");
for (var i = 0; i < data.length; i++) {
$("#EmployeeINfo").append("<td>" + data[i].Name + "</td>");
}
}
});
}
View代码
<table id="dnd-example" onclick="doclick()" cellspacing="1" cellpadding="3" rules="all" border="0" class="listTable" style="border-width:0px;width:100%; padding-left :2px;">
<thead>
<tr>
<th>商品分类代码</th>
<th>商品分类名</th>
<th>序号</th>
<th>操作</th>
</tr>
</thead>
<%foreach (var item in Model)
{
var node = "node--";
var parent = "parent ";
//var bar = "-";
var childOf = "child-of-";
var IdName = "";
var ClassName ="";
//一级分类
if (item.Parent == null)
{
IdName = node + item.Code;
ClassName = parent;
}
//非一级分类
if (item.Parent != null)
{
parentlists = string.Empty;
string parentlist = GetParentList(item.ID);
string ReMoveLastComma = parentlist.Substring(0, parentlist.LastIndexOf('-'));
string[] ToArr = ReMoveLastComma.Split('-'); string str = string.Empty;
for (int i = ToArr.Length; i > 0; i--)
{
str += ToArr[i - 1] + '-';
}
string ReMoveLastBar = str.Substring(0, parentlist.LastIndexOf('-'));
string GetIdName = ReMoveLastBar.Substring(0, ReMoveLastBar.LastIndexOf('-'));
//有子类
if (item.Children != null)
{
IdName = node + ReMoveLastBar;
ClassName = parent + childOf + node + GetIdName;
}
//没有子类
else
{
IdName = node + ReMoveLastBar;
ClassName = childOf + node + GetIdName;
}
}
%>
<tbody>
<tr id="<%=IdName %>" class="<%=ClassName %>" >
<td >
<!--<%= Html.Encode(item.Code)%>-->
<%=Html.ActionLink(Html.Encode(item.Code), "ProductCategoryList", "ProductCategory", new { productId = item.ID }, new {id="productCategoryId" })%>
<%=Html.Hidden("productCategoryId", ViewData["productCategoryId"])%>
</td>
<td>
<%= Html.Encode(item.Name)%>
</td>
<td>
<%= Html.Encode(item.Sequence)%>
</td>
<td>
<%= 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" })%>
</td>
</tr>
</tbody>
<%}%>
</table>Controller代码
public ActionResult ProductCategoryList()
{
Title = "产品类型列表";
var productCategoryList = ProductCategory.GetAll().OrderBy(p => p.Code);
var list = productCategoryList.Where(p => p.Parent == null).ToList();
List<ProductCategory> list_ProductCategory = new List<ProductCategory>(list.Count);
for (var i = 0; i < list.Count; i++)
{
list_ProductCategory.Add(new ProductCategory
{
Code = list[i].Code,
Name = list[i].Name,
Sequence = list[i].Sequence
});
}
return Json(list_ProductCategory);
} public ActionResult ProductCategories(Guid id,string name)
{
Title = "产品类型列表"; //var productCategoryList = ProductCategory.GetChildren(name.).OrderBy(p => p.Code);
// return View(productCategoryList);
return null;
}
// Make sure row is selected when span is clicked
$("table#dnd-example tbody tr span").mousedown(function() {
$($(this).parents("tr")[0]).trigger("mousedown");
var NameOrderBy = "productCategoryId";
LoadCity(NameOrderBy);
});
function LoadCity(NameOrderBy) {
$.ajax({
type: "get",
dataType: "json",
url: "ProductCategories.aspx?Name=" + NameOrderBy,
success: function(msg) {
var data = msg;
$("#EmployeeINfo").html("");
for (var i = 0; i < data.length; i++) {
$("#EmployeeINfo").append("<td>" + data[i].Name + "</td>");
}
}
});
}
View代码
<table id="dnd-example" onclick="doclick()" cellspacing="1" cellpadding="3" rules="all" border="0" class="listTable" style="border-width:0px;width:100%; padding-left :2px;">
<thead>
<tr>
<th>商品分类代码</th>
<th>商品分类名</th>
<th>序号</th>
<th>操作</th>
</tr>
</thead>
<%foreach (var item in Model)
{
var node = "node--";
var parent = "parent ";
//var bar = "-";
var childOf = "child-of-";
var IdName = "";
var ClassName ="";
//一级分类
if (item.Parent == null)
{
IdName = node + item.Code;
ClassName = parent;
}
//非一级分类
if (item.Parent != null)
{
parentlists = string.Empty;
string parentlist = GetParentList(item.ID);
string ReMoveLastComma = parentlist.Substring(0, parentlist.LastIndexOf('-'));
string[] ToArr = ReMoveLastComma.Split('-'); string str = string.Empty;
for (int i = ToArr.Length; i > 0; i--)
{
str += ToArr[i - 1] + '-';
}
string ReMoveLastBar = str.Substring(0, parentlist.LastIndexOf('-'));
string GetIdName = ReMoveLastBar.Substring(0, ReMoveLastBar.LastIndexOf('-'));
//有子类
if (item.Children != null)
{
IdName = node + ReMoveLastBar;
ClassName = parent + childOf + node + GetIdName;
}
//没有子类
else
{
IdName = node + ReMoveLastBar;
ClassName = childOf + node + GetIdName;
}
}
%>
<tbody>
<tr id="<%=IdName %>" class="<%=ClassName %>" >
<td >
<!--<%= Html.Encode(item.Code)%>-->
<%=Html.ActionLink(Html.Encode(item.Code), "ProductCategoryList", "ProductCategory", new { productId = item.ID }, new {id="productCategoryId" })%>
<%=Html.Hidden("productCategoryId", ViewData["productCategoryId"])%>
</td>
<td>
<%= Html.Encode(item.Name)%>
</td>
<td>
<%= Html.Encode(item.Sequence)%>
</td>
<td>
<%= 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" })%>
</td>
</tr>
</tbody>
<%}%>
</table>Controller代码
public ActionResult ProductCategoryList()
{
Title = "产品类型列表";
var productCategoryList = ProductCategory.GetAll().OrderBy(p => p.Code);
var list = productCategoryList.Where(p => p.Parent == null).ToList();
List<ProductCategory> list_ProductCategory = new List<ProductCategory>(list.Count);
for (var i = 0; i < list.Count; i++)
{
list_ProductCategory.Add(new ProductCategory
{
Code = list[i].Code,
Name = list[i].Name,
Sequence = list[i].Sequence
});
}
return Json(list_ProductCategory);
} public ActionResult ProductCategories(Guid id,string name)
{
Title = "产品类型列表"; //var productCategoryList = ProductCategory.GetChildren(name.).OrderBy(p => p.Code);
// return View(productCategoryList);
return null;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货