使用较新版本的jquery获取未捕获的TypeError

时间:2016-06-21 13:52:43

标签: jquery jquery-ui

我正在学习如何使用webgrid和jquery构建父子关系。 这是webgrid

         <div id="main" style="padding:25px; background-color:white;">
            @grid.GetHtml(
            htmlAttributes: new {id="gridT", width="700px" },
            columns:grid.Columns(
                    grid.Column("order.OrderID","Order ID"),
                    grid.Column(header:"Order Date",format:(item)=> string.Format("{0:dd-MM-yyyy}",item.order.OrderDate)),
                    grid.Column("order.CustomerName","Customer Name"),
                    grid.Column("order.CustomerAddress","Address"),

                    grid.Column(format:(item)=>{
                        WebGrid subGrid = new WebGrid(source: item.orderDetails);
                        return subGrid.GetHtml(
                            htmlAttributes: new { id="subT" },
                            columns:subGrid.Columns(
                                    subGrid.Column("Product","Product"),
                                    subGrid.Column("Quantity", "Quantity"),
                                    subGrid.Column("Rate", "Rate"),
                                    subGrid.Column("Amount", "Amount")
                                )                    
                            );
                    })
                )
            )
        </div>

这是jquery

        @section Scripts{
            <script>
                $(document).ready(function () {
                    var size = $("#main #gridT > thead > tr >th").size(); // get total column
                    $("#main #gridT > thead > tr >th").last().remove(); // remove last column
                    $("#main #gridT > thead > tr").prepend("<th></th>"); // add one column at first for collapsible column
                    $("#main #gridT > tbody > tr").each(function (i, el) {
                        $(this).prepend(
                                $("<td></td>")
                                .addClass("expand")
                                .addClass("hoverEff")
                                .attr('title',"click for show/hide")
                            );

                        //Now get sub table from last column and add this to the next new added row
                        var table = $("table", this).parent().html();
                        //add new row with this subtable
                        $(this).after("<tr><td></td><td style='padding:5px; margin:0px;' colspan='" + (size - 1) + "'>" + table + "</td></tr>");
                        $("table", this).parent().remove();
                        // ADD CLICK EVENT FOR MAKE COLLAPSIBLE
                        $(".hoverEff", this).live("click", function () {
                            $(this).parent().closest("tr").next().slideToggle(100);
                            $(this).toggleClass("expand collapse");
                        });
                    });

                    //by default make all subgrid in collapse mode
                    $("#main #gridT > tbody > tr td.expand").each(function (i, el) {
                        $(this).toggleClass("expand collapse");
                        $(this).parent().closest("tr").next().slideToggle(100);
                    });

                });
            </script>
        }

此部分无法正常运行并出现“.live”错误(未捕获TypeError $(...)live不是函数)。我在网上看到这个已被删除 来自较新版本的jquery。

        $(".hoverEff", this).live("click", function () {
                            $(this).parent().closest("tr").next().slideToggle(100);
                            $(this).toggleClass("expand collapse");
                        });

我尝试将其更改为“.on”,但仍然没有运气。我使用的是jquery-1.10.2。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

livedelegate已弃用以前随后被删除。新方法是使用on

相关问题