我使用treetable插件实现了TreeView结构。功能是
1)用户选择日期并按下按钮。
2)单击该按钮,下面的代码运行并绑定树视图。它按预期工作。
现在,问题是,在随后点击按钮时,数据即将到来,但树视图功能无效。它只显示一个普通的HTML。整个代码仅在第一次点击时起作用。 我的Js代码是:
$.when(
$.ajax({
type: "Post",
url: 'EmpScrWithSubordinate.aspx/GetEmpDetails',
async: false,
data: '{"SelectedDate":"' + selectdDate + '","sortExpression":"' + sortExpression + '"}',
contentType: 'application/json; charset=utf-8',
datatype: 'json',
success: function (result) {
$(".tree").append('<ul id="mainUl"></ul>');
var jsonResult = jQuery.parseJSON(result.d);
var tblSuperParent = jsonResult.tblSuperParentList;
var tblChild = jsonResult.tblChildList;
for (var i = 0; i < tblSuperParent.length; i++) {
var InTime = tblSuperParent[i]._InTime;
var OutTime = tblSuperParent[i]._OutTime;
var Late = tblSuperParent[i].late;
var Early = tblSuperParent[i].early;
var Absent = tblSuperParent[i].Absent;
var Request = tblSuperParent[i].Request;
var ParentId = tblSuperParent[i].ParentEmpId;
var parentName = tblSuperParent[i].ParentEmpName;
BindParentTr(ParentId, parentName, InTime, OutTime, Late, Early, Absent, Request);
}
for (var childIndex = 0; childIndex < tblChild.length; childIndex++) {
InTime = tblChild[childIndex]._InTime;
var OutTime = tblChild[childIndex]._OutTime;
var Late = tblChild[childIndex].late;
var Early = tblChild[childIndex].early;
var Absent = tblChild[childIndex].Absent;
var Request = tblChild[childIndex].Request;
var parentId = tblChild[childIndex].ParentEmpId;
var childId = tblChild[childIndex].ChildEmpId;
var childEmpName = tblChild[childIndex].ChildEmpName;
BindChildTr(parentId, childId, childEmpName, InTime, OutTime, Late, Early, Absent, Request);
}
}
})
).done(function () {
$("#tblEmpList").treetable({
expandable: true,
})
})
function BindParentTr(parentId, parentName, InTime, OutTime, Late, Early, Absent,Request) {
$("#tbodyData").append($('<tr>').attr("data-tt-id", parentId));
var $row = $('tr[data-tt-id="' + parentId + '"]');
$row.append('<td>' + parentName + '</td>');
$row.append('<td>' + InTime + '</td>');
$row.append('<td>' + OutTime + '</td>');
$row.append('<td>' + Late + '</td>');
$row.append('<td>' + Early + '</td>');
$row.append('<td>' + Absent + '</td>');
$row.append('<td>' + Request + '</td>');
}
function BindChildTr(parentId, childId, childEmpName, InTime, OutTime, Late, Early, Absent, Request) {
var $row = $('tr[data-tt-id="' + parentId + '"]');
$('<tr data-tt-id=' + childId + ' data-tt-parent-id=' + parentId + '></tr>').insertAfter($row);
var $childRow = $('tr[data-tt-id="' + childId + '"]');
$childRow.append('<td>' + childEmpName + '</td>');
$childRow.append('<td>' + InTime + '</td>');
$childRow.append('<td>' + OutTime + '</td>');
$childRow.append('<td>' + Late + '</td>');
$childRow.append('<td>' + Early + '</td>');
$childRow.append('<td>' + Absent + '</td>');
$childRow.append('<td>' + Request + '</td>');
}
有关如何解决此问题的任何线索?任何帮助将不胜感激。
答案 0 :(得分:0)
我已经通过
解决了我的自我$("#tblEmpList").treetable({expandable: true}, true);