easyui的combotree以及tree,c#后台異步加載的詳細介紹


<p>

前端頁面js:就是這么簡單暴力

///獲取combotree的方法
function GetTree() {
$("#tree").combotree({

width: 175,
url: '/OrganizationManager/Permission/GetTree',
valueField: 'id',
textField: 'text',
editable: false
});

}

控制器以及數據訪問層:

public JsonResult GetTree()
{

string parentNodeId = Request["id"] ?? null;//easyui 會每展開一個節點,往后端傳一個·id

if (string.IsNullOrEmpty(parentNodeId))
{
parentNodeId = "0";
}
List<Model.RunUI.TreeModule> Toptree = bllper.GetSubNodes(parentNodeId);

return Json(Toptree, JsonRequestBehavior.AllowGet);

}

/// <summary>
/// * 獲取菜單的樹的方法*
/// </summary>
/// <param name="parentNodeId"></param>
/// <returns></returns>
public List<Model.RunUI.TreeModule> GetSubNodes(string parentNodeId)
{
string sql = "select * from Per_Module ";
DataTable dt = DbHelperSQL.Query(sql).Tables[0];
List<Model.RunUI.TreeModule> Tree = new List<Model.RunUI.TreeModule>();
Model.RunUI.TreeModule TM = null;
if (dt != null && dt.Rows.Count > 0)
{
DataRow[] rows = dt.Select("ParentModuleID ='" + parentNodeId + "'");

foreach (DataRow item in rows)
{
string id = item["ModuleID"].ToString();
string text = item["Name"].ToString();
TM = new TreeModule();

DataRow[] IsNulRows = dt.Select("ParentModuleID ='" + id + "'");

if (IsNulRows.Length > 0)
{
TM.state = "closed";//這個很關鍵,此節點為closed狀態,才可以展開,才能往后台傳你點擊的id  看到Combotree的異步加載Demo,發現treegrid_data.json中 state="closed" 屬性能把點擊展開的節點Id傳到后台中
}

TM.id = id;
TM.text = text;

Tree.Add(TM);
}
}
return Tree;
}

 

model:類:


public class TreeModule
{

public string id { get; set; }

public string text { get; set; }

public string state { get; set; }
}

就是這么簡單暴力

</P>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM