Home >Web Front-end >JS Tutorial >A brief analysis of the tree usage guide in jQuery EasyUI_jquery
This article records that when leading members to develop a small module function, they needed to use pop-up windows to load tree-like cascade unit selections, and finally decided to use the jQuery EasyUI plug-in for development. However, I encountered a lot of trouble when using the tree plug-in in EasyUI. In order to improve the display speed of the pop-up tree, we use asynchronous loading of node values. First, the root node is loaded, and then the child nodes are loaded according to the clicked node.
Often the results are different from what is expected. I have been confused for a few days. After expansion, the child nodes are dynamically loaded, but after shrinking, the previously filled data cannot be cleared; when expanding for the second time, the child nodes are loaded again. Once again, the data is displayed repeatedly, and there is no method to clear the child nodes. After trying various ways to solve this problem, we can only load the values of child nodes in another form. Save each node value and determine whether it already exists. If it exists, load it without loading.
See examples for two methods:
页面getTreeNode.ashx返回树节点JSON格式数据:
public class getTreeNode : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
DataTable dt = (DataTable)context.Session["viewmaintain"];
string parentId = string.Empty;
string resultStr = string.Empty;
string attributes = string.Empty;
string colName = string.Empty;
string sql = string.Empty;
string Casname = string.Empty;
bool colt = false;
string icon = "icon-profile";
if (!string.IsNullOrEmpty(context.Request.QueryString["pid"]))
{
parentId = context.Request.QueryString["pid"].ToString();
}
if ((!string.IsNullOrEmpty(context.Request.QueryString["coln"])) && (string.IsNullOrEmpty(context.Request.QueryString["casn"])))
{
colName = HttpUtility.UrlDecode(context.Request.QueryString["coln"].ToString());
if (dt != null)
{
bool pt = true;
while (pt)
{
for (int i = 0; i < dt.Rows.Count; i )
{
Casname = dt.Rows[i]["view_colname"].ToString();
if (dt.Rows[i]["view_colname"].ToString() == colName)
{
if (dt.Rows[i]["view_cas"].ToString() != null&&dt.Rows[i]["view_cas"].ToString() !="")
{
colName = dt.Rows[i]["view_cas"].ToString();
}
else
{
colt = true;
sql = dt.Rows[i]["view_sql"].ToString();
pt = false;
}
break;
}
}
}
}
}
if ((!string.IsNullOrEmpty(context.Request.QueryString["casn"])) && (!string.IsNullOrEmpty(context.Request.QueryString["coln"])))
{
string casnName = HttpUtility.UrlDecode(context.Request.QueryString["casn"].ToString());
colName = HttpUtility.UrlDecode(context.Request.QueryString["coln"].ToString());
if (dt != null)
{
for (int i = 0; i < dt.Rows.Count; i )
{
Casname = dt.Rows[i]["view_colname"].ToString();
if (dt.Rows[i]["view_cas"].ToString() == casnName && casnName != colName)
{
colt = true;
sql = dt.Rows[i]["view_sql"].ToString();
break;
}
}
}
}
try
{
if (parentId != "" && colt == true)
{
//此处省略得到数据列表的代码
List
resultStr = "";
resultStr = "[";
if (ltree.Count > 0)
{
foreach (TreeInfo item in ltree)
{
attributes = "";
attributes = "{"cas":"" Casname;
attributes = "","val":"" item._text ""}";
resultStr = "{";
resultStr = string.Format(""id": "{0}", "text": "{1}", "iconCls": "{2}", "attributes": {3}, "state": "closed"", item._id, item._text, icon, attributes);
resultStr = "},";
}
resultStr = resultStr.Substring(0, resultStr.Length - 1);
}
resultStr = "]";
}
else
{
resultStr = "[]";
}
}
catch (Exception ex)
{
resultStr = "出错";
}
context.Response.Write(resultStr);
}
public bool IsReusable
{
get
{
return false;
}
}
}
小弟在此献丑了,不知道各位专家、同仁有没有遇到类似的问题,或者有其它更好的解决办法,欢迎在这交流。