日期:2014-05-17 浏览次数:20503 次
$(document).ready(function() {
var array = new Array();
$("#sl").children().each(function() {
$(this).children().each(function() {
//判断checkbox选中 得到数据 可以push到数组array
});
});
});
//#sl为资源模块 等一级模块的父级ID
------解决方案--------------------
供参考!我上星期写的一个树形结构数据绑定DropDownList
private void BindDrpClass() {
IList<Cargos.CargoCategory> car = Global.CargoCategoryManager.Get();
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Parent", typeof(int));
dt.Columns.Add("Description", typeof(string));
foreach (Cargos.CargoCategory c in car) {
dt.Rows.Add(new object[] { c.Id, c.Name,
c.Parent==null?0:c.Parent.Id, c.Description });
}
DropDownList1.Items.Clear();
//DropDownList1.Items.Add(new ListItem("作为根", "0"));
//DataRow[] drs = dt.Select("Parent= "+dt.Rows[0][2]);
for (int i = 0; i < dt.Rows.Count; i++) {
if (Convert.ToInt32(dt.Rows[i][2]) == 0) {
string classid = dt.Rows[i][0].ToString();
string classname = dt.Rows[i][1].ToString();
//顶级分类显示形式
classname = "├" + classname;
DropDownList1.Items.Add(new ListItem(classname, classid));
int sonparentid = int.Parse(classid);
string blank = " ├──";
//递归子分类方法
BindDrpNode(sonparentid, dt, blank);
}
DropDownList1.DataBind();
}
}
private void BindDrpNode(int parentid, DataTable dt, string blank) {
for (int i = 0; i < dt.Rows.Count; i++) {
if (Convert.ToInt32(dt.Rows[i][2]) == parentid) {
string classid = dt.Rows[i][0].ToString();
string classname = dt.Rows[i][1].ToString();
classname = blank + classname;
DropDownList1.Items.Add(new ListItem(classname, classid));
int sonparentid = int.Parse(classid);
string blank2 = " " + blank + "──";
BindDrpNode(sonparentid, dt, blank2);
}
}
}
------解决方案--------------------
三层循环:
StringBuilder test = new StringBuilder();
foreach (TreeNode node in TreeView1.Nodes)
{
if(!node.Selected) continue;
test.Append(node.Text);
foreach (TreeNode SecondNode in node.ChildNodes)
{
if(!SecondNode.Selected) continue;
test.Append(SecondNode.Text);
foreach (TreeNode ThridNode in node.ChildNodes)
{
if(!ThridNode.Selected) continue;
test.Append(ThridNode.Text);
}
}
//这里操作你的数据保存方法。
//test.ToString();就是你要的数据。
}
递归:
private string reText(TreeNodeCollection nodes)
{
StringBuilder test = new StringBuilder();
foreach (TreeNode node in nodes)
{
if(!node.Selected) conti