asp.net+extjs3.2.0
运行的结果是第一个节点打开关不上,最后两个节点打不开,只有第二三个节点是好的
Extjs代码:
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL="Extjs3.2.0/resources/images/default/s.gif";
var Tree = Ext.tree;
var tree = new Tree.TreePanel({
el:'west_content',//渲染到
useArrows:true,
autoHeight:true,
split:true,
lines:true,
autoScroll:true,
animate:true,
enableDD:true,
border:false,
containerScroll: true,
loader: new Tree.TreeLoader({
dataUrl:'GetTrees.ashx'
})
});
var root = new Tree.AsyncTreeNode({
text: '机型零部件菜单',
draggable:true,
id:'0'
});
tree.setRootNode(root);
tree.render();
root.expand();
var viewport = new Ext.Viewport({
layout:'border',
items:[{
region:'west',
id:'west',
title:'菜单导航',
split:true,
width: 200,
minSize: 200,
maxSize: 400,
collapsible: true,
margins:'60 0 2 2',
cmargins:'60 5 2 2',
layout:'fit',
layoutConfig:{ activeontop:true},
defaults: { bodyStyle: 'margin:0;padding:0;'},
items:
new Ext.TabPanel({
border:false,
activeTab:0,
tabPosition:'bottom',
items:[{
contentEl:'west_content',
title:'系统管理',
autoScroll:true,
bodyStyle:'padding:5px;'
}]
})
},{
region:'center',
el:'center',
deferredRender:false,
margins:'60 0 2 0',
html:'<iframe id="center-iframe" width="100%" height=100% name="main" frameborder="0" scrolling="auto" style="border:0px none; background-color:#BBBBBB; " ></iframe>',
autoScroll:true
},
{
region:'south',
margins:'0 0 0 2',
border:false,
html:'<div class="menu south">Copyright © 2010 Kimi Yang All Rights Reserved</div>'
}
]
});
setTimeout(function(){
Ext.get('loading').remove();
Ext.get('loading-mask').fadeOut({remove:true});
}, 250)
});
GetTrees.ashx:
namespace test4.web
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class GetTrees : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string strSql = "select hf_Components.*,hf_model.* from hf_Components left join hf_model on hf_Components.com_modelId=hf_model.mod_id";
string strMySql = "select distinct hf_Components.com_modelId,hf_model.mod_id,hf_model.mod_name from hf_Components left join hf_model on hf_Components.com_modelId=hf_model.mod_id";
dbOperator db = new dbOperator();
DataTable dt = db.Execute(strSql);
DataTable table = db.Execute(strMySql);
string strResult = "[";
if (dt.Rows.Count > 0)
{
if (table.Rows.Count > 0)
{
for (int i = 0; i < table.Rows.Count; i++)
{
DataRow[] dr = table.Select("mod_id='" + table.Rows[i]["mod_id"] + "'");
strResult = DtTreeToJson(dt, strResult, dr);
}
}
}
strResult += "]";
context.Response.ContentType = "text/plain";
context.Response.Write(strResult.ToString());
context.Response.End();
}
private static string DtTreeToJson(DataTable dt, string strResult, DataRow[] dr)
{
if (dr.Length > 0)
{
strResult += "{";
strResult += "text:'" + dr[0]["mod_name"] + "',";
strResult += "id:'" + dr[0]["mod_id"] + "',";
DataRow[] drChild = dt.Select("com_modelId='" + dr[0]["mod_id"] + "'");
if (drChild.Length > 0)
{
strResult += "leaf:false,";
strResult += "children:[";
strResult = DtTreeToJsons(dt, strResult, drChild);
strResult += "]";
}
strResult += "}";
if (dr.Length != dr.Length - 1)
{
strResult += ",";
}
}
return strResult;
}
private static string DtTreeToJsons(DataTable dt, string strResult, DataRow[] dr)
{
if (dr.Length > 0)
{
for (int i = 0; i < dr.Length; i++)
{
strResult += "{";
strResult += "text:'" + dr[i]["com_Name"] + "',";
strResult += "id:'" + dr[i]["com_ID"] + "',";
DataRow[] drChild = dt.Select("com_ID='" + dr[i]["com_ID"] + "'");
if (drChild.Length > 0)
{
strResult += "leaf:true";
}
strResult += "}";
if (i != dr.Length - 1)
{
strResult += ",";
}
}
}
return strResult;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
如果实在看不懂,就请加454528291赐教,在此谢过!很急!!!
[解决办法]
看着很复杂啊,先把Tree提取出来看看能否显示正常
下面的代码你可以参考,但不保证能跑通。
- HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <div id="tree"> </div> <script type="text/javascript"> var show = "show"; var url = "url"; Ext.onReady(function () { var treeLoader = new Ext.tree.TreeLoader({ dataUrl: '/TreeHandler.ashx?show=' + show + '&url=' + url, listeners: { scope: this, 'beforeload': function (loader, node) { } } }); var treeRoot = new Ext.tree.AsyncTreeNode({ id: "-1", text: "根", nodeType: 'async' }); var eTree = new Ext.tree.TreePanel({ autoScroll: true, containerScroll: true, border: false, height: 480, region: 'center', margins: '3 0 20 0', root: treeRoot, loader: treeLoader, renderTo: 'tree', listeners: { scope: this, 'click': function (node, e) { } } }); treeRoot.expand(false, true); }); </script> </body></html>