加载树有两种方法,一是通过js,二是直接在后台绑定。
第一种方法:
<ext:TreePanel ID="ClientJobTree" runat="server" Icon="Note" Border="false" AutoScroll="true"> <Listeners> <Before Fn="LoadeNode" /> </Listeners> </ext:TreePanel>
脚本代码:
代码
function LoadeNode(node) {
Coolite.AjaxMethods.NodesBind(node.id, {
success: function(result) {
var data = eval("(" + result + ")");
node.loadNodes(data);
},
failure: function(errorMsg) {
Ext.Msg.alert('Failure', errorMsg);
}
});
}
后台代码:
加载一级和二级菜单
代码
/// <summary>
/// 绑定树
/// </summary>
public void TreeBind()
{
string projectID = Request.QueryString["ProjectID"].ToString();
string Name = TextFieldName.Text.ToString();
string clientGroup = ExtComboBoxParameterGroup.SelectedItem.Text.ToString();
string services = ExtComboBoxParameterServices.SelectedItem.Text.ToString();
Coolite.Ext.Web.TreeNode root = new Coolite.Ext.Web.TreeNode();
//通过ProjectID找到Name
PROJ_ProjectBase projectBase = this.logic.GetProjectBaseByProjectID(projectID);
root.Text = projectBase.project_name;
ClientJobTree.Root.Add(root);
List<PROJ_ClientJob> rootList = this.logic.GetClientJob(projectID, Name, services,clientGroup);
foreach (PROJ_ClientJob item in rootList)
{
string clientID = item.clientJob_id;
string clientName = item.job_name;
AsyncTreeNode rootNode = new AsyncTreeNode();
rootNode.NodeID = clientID;
rootNode.Text = clientName;
rootNode.Icon = Icon.Folder;
rootNode.Expanded = true;
root.Nodes.Add(rootNode);
}
}
绑定三级菜单
代码
/// <summary>
/// 树节点的绑定
/// </summary>
/// <param name="nodes">节点集合</param>
/// <param name="parentNodeID">父节点号</param>
public void NodeBind(Coolite.Ext.Web.TreeNodeCollection nodes, string parentNodeID)
{
string projectID = Request.QueryString["ProjectID"].ToString();
List<PROJ_WBS> wbsList = this.logic.GetProjectWbsByClientJobID(parentNodeID, projectID);
foreach (PROJ_WBS item in wbsList)
{
Coolite.Ext.Web.AsyncTreeNode treeNode = new Coolite.Ext.Web.AsyncTreeNode();
treeNode.NodeID = item.wbs_id;
treeNode.Text = item.wbs_name;
treeNode.Icon = Icon.Folder;
treeNode.Expanded = false;
nodes.Add(treeNode);
}
}
/// <summary>
/// 绑定树节点
/// </summary>
/// <param name="nodeID"></param>
/// <returns></returns>
[AjaxMethod]
public string NodesBind(string nodeID)
{
Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
this.NodeBind(nodes, nodeID);
return nodes.ToJson();
}
第二种方法:(直接在后台绑定,不需要<beforeLoad fn="" />
代码
/// <summary>
/// 绑定树
/// </summary>
public Coolite.Ext.Web.TreeNodeCollection TreeBind()
{
Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
string projectID = Request.QueryString["ProjectID"].ToString();
string name = TextFieldName.Text.ToString();
string clientGroup = ComboBoxClientGroup.SelectedItem.Text.ToString();
string services = ComboBoxClientService.SelectedItem.Text.ToString();
Coolite.Ext.Web.TreeNode root = new Coolite.Ext.Web.TreeNode();
//通过ProjectID找到Name
PROJ_ProjectBase projectBase = this.logic.GetProjectBaseByProjectID(projectID);
root.Text = projectBase.project_name;
ClientJobTree.Root.Add(root);
List<PROJ_ClientJob> rootList = this.logic.GetClientJob(projectID, name, services, clientGroup);
foreach (PROJ_ClientJob item in rootList)
{
string clientID = item.clientJob_id;
string clientName = item.job_name;
Coolite.Ext.Web.TreeNode supernode = new Coolite.Ext.Web.TreeNode();
supernode.NodeID = clientID;
supernode.Text = clientName;
supernode.Icon = Icon.Folder;
supernode.Expanded = true;
root.Nodes.Add(supernode);
this.NodeBind(clientID, supernode);
}
return ClientJobTree.Root;
}
/// <summary>
/// 树节点的绑定
/// </summary>
/// <param name="parentNodeID">父节点号</param>
/// <param name="parentcode">父节点</param>
public void NodeBind(string parentNodeID, Coolite.Ext.Web.TreeNode parentcode)
{
string projectID = Request.QueryString["ProjectID"].ToString();
List<PROJ_WBS> wbsList = this.logic.GetProjectWbsByClientJobID(parentNodeID, projectID);
foreach (PROJ_WBS item in wbsList)
{
Coolite.Ext.Web.TreeNode node = new Coolite.Ext.Web.TreeNode();
string wbsID = item.wbs_id;
node.NodeID = item.wbs_id;
node.Text = item.wbs_name;
node.Icon = Icon.Folder;
//node.Expanded = false;
parentcode.Nodes.Add(node);
this.NodeBind(wbsID, node);
}
}