2016-06-21 4 views
-1

私はwebgridとjqueryを使用して親子関係を構築する方法を学習しています。このセクションでは、作業と ".live"(キャッチされない例外TypeErrorの$(...)住んでエラーに実行されていないjqueryの新しいバージョンで未知のTypeErrorを取得する

 @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> 
     } 

は、ここでは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の新しいバージョンの から削除されています。

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

これを「.on」に変更しようとしましたが、まだ運がありませんでした。 jquery-1.10.2を使用しています。どうすればこの作品を作れますか?

答えて

0

liveおよびdelegateは廃止されました。が前に削除されました。新しい方法はonを使用することです。

+0

このコードにonを適用するにはどうすればよいですか?私のためにはうまくいきません。 – user2320476

+0

@ user2320476: 'on'(と' live'と 'delegate')のドキュメンテーションは明確な例を示しています$(" hoverEff "、this).on(" click "、function(){ 'live'と' delegate'を使っていたところで 'on'を使う方法について学んでいますが、最初に学ぶべきことはドキュメンテーションはあなたの友人*です:$(document).on ( "click"、 ".hoverEff"、function(){/*...*/}); ' –

+0

私はこれを試しても動作しません。 slideToggle(100); $(this)(this。)(this。 ).toggleClass( "expand collapse"); }); – user2320476

関連する問題