jQuery EasyUI 1.3.1 官方下载地址:
$(function () {
$(document).ready(function () {
$.post("/ORG/ajax/getRoles.aspx", {}, function (json) {
$("#tt77").tree({
data: json,
onClick: function (node) {
//----
$('#hid').val(node.id);
$('#wbs').val(node.attributes);
var b = $('#tt77').tree('isLeaf', node.target);
if (!b) {
return;
}
//------
$.post("/ORG/ajax/getRoles.aspx?id=" + node.id, {
"id": node.id
}, function (json) {
$('#tt77').tree('append', {
parent: node.target,
data: json
});
}, "json");
},
checkbox: true,cascadeCheck:false
});
}, "json");
});
});
内容:
后台代码:
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
protected void Page_Load(object sender, EventArgs e)
{
string roleId = Request.QueryString["id"];
List rolesList = null;
RendString(Obj2Json(data2Json(rolesList)));
}
protected void RendString(string content)
{
Response.Clear();
Response.Write(content);
Response.End();
}
private List data2Json(List list)
{
List tnList = new List();
sys_Roles_bean bean = null;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < list.Count; i++)
{
bean = list[i];
UTC_IBMP.SYS.TreeNode tn = new UTC_IBMP.SYS.TreeNode(bean.RoleID.ToString(), bean.RoleName, "icon-role");
tn.attributes = bean.RoleWBS;
tnList.Add(tn);
}
return tnList;
}
public static string Obj2Json(T data)
{
try
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(data.GetType());
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, data);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
catch
{
return null;
}
}
阅读(6377) | 评论(0) | 转发(0) |