在页面放置一个隐藏文本域
<ext:Hidden runat="server" Enabled="false" ID="hidFlag">
<Listeners>
<Enable Handler="refreshTree(#{pnlTree});"/> //pnlTree就是我左边的树
</Listeners>
</ext:Hidden>
当通过Ajax方法更改数据后设置 this.hidFlag.Enabled = true;
随即调用
<script type="text/javascript">
function refreshTree(tree) {
Coolite.AjaxMethods.RefreshMenu({
success: function(result) {
var nodes = eval(result);
tree.root.ui.remove();
tree.initChildren(nodes);
tree.root.render();
}
});
}
</script> 注:必须调用JS重新渲染,不然虽然绑定了数据,但原本就是ajax的数据绑定,所以页面前端没有同时渲染而已
后台对应一个AjaxMethod
[AjaxMethod]
public string RefreshMenu()
{
Coolite.Ext.Web.TreeNodeCollection nodes = this.BuildTree(null);
return nodes.ToJson();
}//注意:
BuildTree(null)为我迭代构建树的方法,但注意返回类型 private Coolite.Ext.Web.TreeNodeCollection BuildTree(Coolite.Ext.Web.TreeNodeCollection nodes)
{
if (nodes == null)
{
nodes = new Coolite.Ext.Web.TreeNodeCollection();
}
List<EntityUserInfo> list = new BLLUserInfo().GetAllUser();
foreach (var lis in list)
{
_parent = lis.Id;
Coolite.Ext.Web.TreeNode childNode = new Coolite.Ext.Web.TreeNode();
childNode.Text = lis.UserName;
childNode.NodeID = lis.Id.ToString();
childNode.Icon = Icon.UserGreen;
if (lis.HasSon)
{
childNode.Expanded = true;
childNode.Icon = lis.ParentId == 0?Icon.UserHome:Icon.UserRed;
childNode.Leaf = false;
BuildTree(childNode.Nodes);
}
nodes.Add(childNode);
}
return nodes;
}页面TreePanl:<ext:TreePanel ID="tp" runat="server" Header="false" Border="false" AutoScroll="true"
Lines="false" CollapseFirst="false" ContainerScroll="true" RootVisible="true">
<Root>
<ext:AsyncTreeNode Text="分类目录" NodeID="root" Expanded="true" />
</Root>
动态加载的子节点内容...
</ext:TreePanel>
js中红色的那句话把root的ui删了,虽然能解决刷新的问题,但页面写死的那个Root没有了...
求教有没有别的办法让页面刷新时显示 Root节点,或者刷新时不删除Root的UI
<ext:Hidden runat="server" Enabled="false" ID="hidFlag">
<Listeners>
<Enable Handler="refreshTree(#{pnlTree});"/> //pnlTree就是我左边的树
</Listeners>
</ext:Hidden>
当通过Ajax方法更改数据后设置 this.hidFlag.Enabled = true;
随即调用
<script type="text/javascript">
function refreshTree(tree) {
Coolite.AjaxMethods.RefreshMenu({
success: function(result) {
var nodes = eval(result);
tree.root.ui.remove();
tree.initChildren(nodes);
tree.root.render();
}
});
}
</script> 注:必须调用JS重新渲染,不然虽然绑定了数据,但原本就是ajax的数据绑定,所以页面前端没有同时渲染而已
后台对应一个AjaxMethod
[AjaxMethod]
public string RefreshMenu()
{
Coolite.Ext.Web.TreeNodeCollection nodes = this.BuildTree(null);
return nodes.ToJson();
}//注意:
BuildTree(null)为我迭代构建树的方法,但注意返回类型 private Coolite.Ext.Web.TreeNodeCollection BuildTree(Coolite.Ext.Web.TreeNodeCollection nodes)
{
if (nodes == null)
{
nodes = new Coolite.Ext.Web.TreeNodeCollection();
}
List<EntityUserInfo> list = new BLLUserInfo().GetAllUser();
foreach (var lis in list)
{
_parent = lis.Id;
Coolite.Ext.Web.TreeNode childNode = new Coolite.Ext.Web.TreeNode();
childNode.Text = lis.UserName;
childNode.NodeID = lis.Id.ToString();
childNode.Icon = Icon.UserGreen;
if (lis.HasSon)
{
childNode.Expanded = true;
childNode.Icon = lis.ParentId == 0?Icon.UserHome:Icon.UserRed;
childNode.Leaf = false;
BuildTree(childNode.Nodes);
}
nodes.Add(childNode);
}
return nodes;
}页面TreePanl:<ext:TreePanel ID="tp" runat="server" Header="false" Border="false" AutoScroll="true"
Lines="false" CollapseFirst="false" ContainerScroll="true" RootVisible="true">
<Root>
<ext:AsyncTreeNode Text="分类目录" NodeID="root" Expanded="true" />
</Root>
动态加载的子节点内容...
</ext:TreePanel>
js中红色的那句话把root的ui删了,虽然能解决刷新的问题,但页面写死的那个Root没有了...
求教有没有别的办法让页面刷新时显示 Root节点,或者刷新时不删除Root的UI
我的这个Demo右侧是一个表单,具体业务逻辑是,点击菜单,表单显示该节点对应的信息,操作更改后,刷新TreePanl的内容
我的做法是,在页面放置一个隐藏文本域
<ext:Hidden runat="server" Enabled="false" ID="hidFlag">
<Listeners>
<Enable Handler="refreshTree(#{pnlTree});"/> //pnlTree就是我左边的树
</Listeners>
</ext:Hidden>
当通过Ajax方法更改数据后设置 this.hidFlag.Enabled = true;
随即调用
<script type="text/javascript">
function refreshTree(tree) {
Coolite.AjaxMethods.RefreshMenu({
success: function(result) {
var nodes = eval(result);
tree.root.ui.remove();
tree.initChildren(nodes);
tree.root.render();
}
});
}
</script> 注:必须调用JS重新渲染,不然虽然绑定了数据,但原本就是ajax的数据绑定,所以页面前端没有同时渲染而已
后台对应一个AjaxMethod
[AjaxMethod]
public string RefreshMenu()
{
Coolite.Ext.Web.TreeNodeCollection nodes = this.BuildTree(null);
return nodes.ToJson();
}//注意:
BuildTree(null)为我迭代构建树的方法,但注意返回类型 private Coolite.Ext.Web.TreeNodeCollection BuildTree(Coolite.Ext.Web.TreeNodeCollection nodes)
{
if (nodes == null)
{
nodes = new Coolite.Ext.Web.TreeNodeCollection();
}
List<EntityUserInfo> list = new BLLUserInfo().GetAllUser();
foreach (var lis in list)
{
_parent = lis.Id;
Coolite.Ext.Web.TreeNode childNode = new Coolite.Ext.Web.TreeNode();
childNode.Text = lis.UserName;
childNode.NodeID = lis.Id.ToString();
childNode.Icon = Icon.UserGreen;
if (lis.HasSon)
{
childNode.Expanded = true;
childNode.Icon = lis.ParentId == 0?Icon.UserHome:Icon.UserRed;
childNode.Leaf = false;
BuildTree(childNode.Nodes);
}
nodes.Add(childNode);
}
return nodes;
}这样它不刷都不由它,希望你能明了,OK,打完收功!
以上所有黑体字符都属于本人从网上搜索转载而来的文字,期望能帮到LZ。