在Javascript中将子TR锁定到父TR

时间:2014-07-17 17:09:27

标签: javascript jquery html

我在Javascript中创建了一个表,在使用tablesorter插件后我无法使用扩展行功能。我只能在使用tablesorter之前展开隐藏的TR。

我查了一下,似乎我必须用我的父TR锁定隐藏的TR孩子

我的表格代码如下:

$('<tr>').html("<td class='IndicatedDispatch'></td>" + "<td>" + $(this).find("TripID").text() + "</td><td>"
       + $(this).find("RouteNum").text() + "</td><td>"
       + monthArray[theMonth] + " " + $(this).find("ArriveDate").text().substr(8,8).replace("T"," ") + "</td><td>"
       + monthArray[theMonth] + $(this).find("DepartDate").text().substr(8, 8).replace("T", " ") + "</td><td>"
       + $(this).find("CommodityHandle").text() + "</td>").addClass($(this).find("IsDispatched").text() === "0" ? "DispatchNo" : "DispatchYes").appendTo('#dallas');

        $('<tr>').html("<td colspan='6'><p>" + $(this).find("DeliverySequence").text() + "</p></td>").hide().appendTo('#dallas');
    });

    $("#dallas").tablesorter();

    setTimeout(function () {
        $("tr").click(function (event) {
            event.stopPropagation();
            var $target = $(event.target);
            $target.parent().next().slideToggle();
        });
    }, 1000);

基本上,如何在对表格进行排序后使用我的setTimeout函数进行扩展?

非常感谢。

试过这个,现在根本没有扩展:

 $('<tr>').html("<td class='IndicatedDispatch'></td>" + "<td>" + $(this).find("TripID").text() + "</td><td>"
       + $(this).find("RouteNum").text() + "</td><td>"
       + monthArray[theMonth] + " " + $(this).find("ArriveDate").text().substr(8,8).replace("T"," ") + "</td><td>"
       + monthArray[theMonth] + $(this).find("DepartDate").text().substr(8, 8).replace("T", " ") + "</td><td>"
       + $(this).find("CommodityHandle").text() + "</td>").addClass($(this).find("IsDispatched").text() === "0" ? "DispatchNo" : "DispatchYes").appendTo('#dallas');

        $('<tr data-associatedId="hiddenTr1">').html("<td colspan='6'><p>" + $(this).find("DeliverySequence").text() + "</p></td>").hide().appendTo('#dallas');
    });

    $("#dallas").tablesorter();

    setTimeout(function () {
 $("tr").click(function (event) {
     event.stopPropagation();
     var $target = $(event.target);
     $('#' + $target.attr('data-associatedId')).slideToggle();
 });
 }, 1000);

0 个答案:

没有答案