我正在尝试用ajax加载Fancytree。贝娄是我的代码,调用方法时我没有收到任何错误。此外,我已经验证数据返回到ajax方法。但是无法将子对象加载到树中。有人可以帮我确定确切的问题吗?
Ajax电话:
lazyLoad: function (event, data) {
data.result = $.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "frmCSMWorkstation.aspx/GetList",
error: function (xhr, status, error) {
// Display a generic error for now.
alert("AJAX Error!");
}
});
},
Webmethod
[WebMethod]
public static string GetList()
{
try
{
using (var context = new DataEntities())
{
var objGroup = context.ObjectGroups.Select(s => new { title = s.Name.Replace("/", ""), key = s.ObjectGroupUid }).Take(5);
var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(objGroup);
return json;
}
}
catch (Exception)
{
throw;
}
}
从Webmethod返回的数据
[
{"title":"Title1","key":"2c6ac17b-cbb5-e511-8213-00215a9c800e"},
{"title":"Title2","key":"8db871b2-2db6-e511-8213-00215a9c800e"},
{"title":"Title3","key":"e409320e-31b6-e511-8213-00215a9c800e"},
{"title":"Title4","key":"bd7f22b2-31b6-e511-8213-00215a9c800e"}
]
答案 0 :(得分:0)
您可能会使用source
选项加载初始数据。仅在展开延迟节点时才会触发lazyLoad
。
像
source: {
url: "frmCSMWorkstation.aspx/GetList",
},