【问题标题】:Update Dynamic data in treetable plugin更新树表插件中的动态数据
【发布时间】:2015-01-14 08:09:40
【问题描述】:

我使用 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>');

    }

关于如何解决此问题的任何线索?任何帮助将不胜感激。

【问题讨论】:

    标签: jquery asp.net ajax json treetable


    【解决方案1】:

    我自己解决了这个问题

    $("#tblEmpList").treetable({expandable: true}, true);
    

    参考:https://github.com/ludo/jquery-treetable/issues/128

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      相关资源
      最近更新 更多