我從http://www.jeasyui.com使用名爲'tree'的控件。但在我的情況下,我想加載在第一個最高級別,然後點擊其中一個節點加載它的子節點。動態樹形控件
<ul id="tt" checkbox="true" animate="true"></ul>
$(function() {
$('#tt').tree({
data: @Html.Raw(Model.Tree)
});
});
此功能
我獲得選擇的節點的孩子的節點從DB:
$(function() {
$('#tt').tree({
onBeforeExpand: function(node) {
var hospitalId = node.id;
$.getJSON('@Url.Action("LoadDepartments")', { hospitalId: hospitalId }, function() {
});
}});});
[HttpGet]
public ActionResult LoadDepartments(Guid hospitalId)
{
LoadHospitals();
var departments = _templateAccessor.GetDepartments(hospitalId);
var hospital = tree.Where(obj => obj.id == hospitalId.ToString()).FirstOrDefault();
if (hospital != null)
{
foreach (var department in departments)
{
DataTreeModel dep = new DataTreeModel();
dep.id = department.Id.ToString();
dep.text = department.Name;
dep.state = "closed";
hospital.children.Add(dep);
hospital.state = "open";
}
}
var result = SerializeToJsonString(tree);
return Json(result, JsonRequestBehavior.AllowGet);
}
在方法LoadDepartments我有正確的結構,但樹不顯示新元素。問題是如何清理樹的以前的內容並填充新的內容,也許我做錯了什麼?
您的JavaScript代碼需要一些JSON,但您的操作會返回一個視圖。那是對的嗎? – Suhas 2012-08-14 10:50:24
我糾正,但結果是相同的 – revolutionkpi 2012-08-14 11:12:33
我可能會用'return Json(hospital,JsonRequestBehavior.AllowGet)替換最後兩行;' – Suhas 2012-08-14 11:23:29