学习日记3、投机取巧使两个表的数据同时在一个treeGrid中显示

不多说了直接上代码,

$('#List').treegrid({
url: '@Url.Action("GetList")',
$(window).width() - 10,
methord: 'post',
height: $(window).height() - 35,
fitColumns: true,
treeField: 'Name',
idField: 'Id',
pagination: false,
striped: true, //奇偶行是否区分
singleSelect: true,//单选模式
//rownumbers: true,//行号
columns: [[
{ field: 'Id', title: 'ID', 80,hidden:true },
{ field: 'Name', title: '名称', 400, sortable: true },
{ field: 'DutyName', title: '团队名称', 80,sortable:true ,hidden:true},
{ field: 'Remark', title: '说明', 80, sortable: true, hidden: true },
{ field: 'CreateTime', title: '创建时间', 80, sortable: true, hidden: true },
{ field: 'CreatePerson', title: '创建人员', 80, sortable: true, hidden: true },
{field: 'Enable', title: '是否启用', '60', align: 'center', hidden: true},
{ field: 'ParentId', title: '父级Id', 80, sortable: true, hidden: true },
{ field: 'DepartmentId', title: '部门Id', 80, sortable: true, hidden: true },
{ field: 'IsLast', title: '是否为空', 80, sortable: true, hidden: true }
]]
});

这个整个treeGrid  的JS代码其中3-9是团队人员表的数据,第十条是部门表的数据,1-2是两个表共有的数据。

1-2条是这个的主要部分,因为只有field一样两个表的数据才能绑定上,后台区分是根据传到后台的Id

[HttpPost]
public JsonResult GetList(string id)
{
//根据Id区分部门表和团队人员表信息进行展示树状图(投机取巧:使团队表和部门表的名称Name一样使能够在前台展示出组合网格)
id = id ?? "0";
List<SysStructModel> modellist = S_BLL.GetByParentId(id);
if (modellist.Count()>0)
{
//List<SysStructModel> list = S_BLL.GetByParentId(id);
var json = from r in modellist
select new SysStructModel()
{
Id = r.Id,
Name = r.Name,
ParentId = r.ParentId,
Sort = r.Sort,
Higher = r.Higher,
Enable = r.Enable,
Remark = r.Remark,
CreateTime = r.CreateTime,
state = (S_BLL.GetByParentId(r.Id).Count() > 0||m_BLL.GetList(r.Id).Count() > 0) ? "closed" : "open",
IsLast = r.IsLast
};

return Json(json);
}
else
{
List<Cst_PersonnelModel> list = m_BLL.GetList(id);
var json = (from r in list
select new Cst_PersonnelModel()
{
Id = r.Id,
Name =r.DutyName+r.Name+"-"+"["+r.Remark+"]",
DutyName = r.DutyName,
Remark = r.Remark,
CreateTime = r.CreateTime,
CreatePerson = r.CreatePerson,
ParentId = r.ParentId,
DepartmentId = r.DepartmentId,
Sort = r.Sort,
Enable = r.Enable,
state = m_BLL.GetparentById(r.Id).Count() > 0 ? "closed" : "open",
IsLast=null
}).ToArray();
return Json(json);
}


}

这样的话就能够很好的在前台展现出两个表联合的treeGrid了,总感觉这样功能是出来,但是感觉很不太对,如果您有其他更好的方法请留言。

原文地址:https://www.cnblogs.com/Wxinchun/p/8637137.html