首先看一下我的前台代码
jQuery(function() {
$('#tree').tree({
url: '../Handlers/ECTree.ashx',
method: 'get',
animate: true,
// data: [{
// "id":19,
// "text":"销售类",
// "iconCls":"icon-save",
// "children": [{
// "id":21,
// "text": "EC销售类01",
// "checked": true,
// "children": [{
// "id": 23,
// "text": "ESC销售类01",
// "attributes": {
// "url": "/demo/book/abc",
// "price": 100
// }
// }]
// },{
// "id":22,
// "text": "EC销售类02",
// "state":"open",
// "attributes":{
// "url":"/demo/book/abc",
// "price":100
// },
// "children": [{
// "id": 25,
// "state": "open",
// "text": "ESC销售类02",
// "state": "open",
// "children": [{
// "id": 27,
// "text": "EI销售类01",
// "attributes": {
// "url": "/demo/book/abc",
// "price": 100
// }
// }],
// "children": [{
// "id": 28,
// "text": "EI销售类02",
// "attributes": {
// "url": "/demo/book/abc",
// "price": 100
// }
// }]
// }]
// }]
//}] ,
loadFilter: function (data) {
alert(data);
if (data.d) {
return data.d;
} else {
return data;
}
}
});
});
我的一般处理文件的代码:
public void ProcessRequest(HttpContext context)
{
IList<EC> ec = ECBLL.GetList();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("[");
foreach (EC row in ec)
{
if (stringBuilder.Length != 1)
{
stringBuilder.Append(",");
}
stringBuilder.Append("{");
stringBuilder.Append("\"id\":\"" + row.ECID + "\",");
stringBuilder.Append("\"text\":\"" + row.ECName + "\",");
stringBuilder.Append("\"children\":\"" + row.ParentID);
stringBuilder.Append("}");
}
stringBuilder.Append("]");
//stringBuilder.Remove(0, 1);
//stringBuilder.Remove(stringBuilder.Length-1, 1);
//JavaScriptSerializer jss = new JavaScriptSerializer();
//string jsons = jss.Serialize(stringBuilder);
context.Response.Write(stringBuilder);
}
我这样写拿到的json数据不对,最外边多了{},而且这样写不能拿到子节点的数据,可能需要更多的判断和逻辑,我是初学者,有没有大神教我?