后台代码:
public JsonResult GetAnYou()
{
var aySql = "select * from T_User";
var ayResult = dbContext.Database.SqlQuery
var data = ayResult.Select(p => new { MC = p.MC, DM = p.DM, FDM = p.FDM });
return Json(new { data = data }, JsonRequestBehavior.AllowGet);
}
JS代码:
$.ajax({
url: "@Url.Content("~/Document/GetAnYou")",
data: { "ajlb": ajlxVal },
cache: false,
async: false,
success: function (result) {
$.each(result.data, function (index, firstValue) {
if (firstValue.FDM == 0) {
mydtree.add(firstValue.DM, 0, firstValue.MC, '', firstValue.MC, "_self", false);
$.each(result.data, function (index, secondValue) {
if (secondValue.FDM == firstValue.DM) {
mydtree.add(secondValue.DM, firstValue.DM, secondValue.MC, '', secondValue.MC, "_self", false);
$.each(result.data, function (index, thirdValue) {
if (thirdValue.FDM == secondValue.DM) {
mydtree.add(thirdValue.DM, secondValue.DM, thirdValue.MC, "javascript:setvalue('" + thirdValue.DM + "','" + thirdValue.MC + "')", thirdValue.MC, "_self", false);
}
});
}
});
}
});
document.write(mydtree);
}
});
....一样的啊