TreePanel的刷新,以下做为一个例子:
当点击查询按钮时,TreePanel将重新刷新一次。
前台代码:
代码
<ext:Button ID="ButtonQuery" runat="server" Text="Search" meta:resourcekey="ButtonQueryResource"
StyleSpec="padding-left:105px;">
<Listeners>
<Click Handler="Search(#{ClientJobTree});" />
</Listeners>
</ext:Button>
脚本代码:
代码
function Search(tree) {
Coolite.AjaxMethods.Query({
success: function(result) {
var nodes = eval(result);
tree.root.ui.remove();
tree.initChildren(nodes);
tree.root.render();
tree.el.unmask();
},
failure: function(msg) {
tree.el.unmask();
Ext.Msg.alert('Failure', '未能加载数据');
}
});
}
后台代码:
/// <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); } } /// <summary> /// 查询事件 /// </summary> [AjaxMethod] public string Query() { Coolite.Ext.Web.TreeNodeCollection nodes = this.TreeBind(); return nodes.ToJson(); }