2016-05-19 56 views
1

我想循環遍歷劍道網格的每一行並僅檢查特定行的複選框。以下是我迄今嘗試的方法。檢查劍道網格中的特定複選框

function LoadControllerGrid(list) { 

     $("#controllerGrid1").kendoGrid({ 
      data Source: { 
       type: "json", 
       // contentType: "application/json; charset=utf-8", 
       transport: { 
        read: { 
         url: "@Html.Raw(Url.Action("GetControllerList", "Account"))", 
         type: "POST", 
         dataType: "json" 
        }, 

       }, 
       schema: { 
        model: { 
         id: "Id", 
         fields: { 
          'Id': { type: "string" }, 
          'Name': { type: "string" }, 
          'Description': { type: "string" }, 
          'URL': { type: "string" }, 
         }, 

        }, 
        data: 'data', 
        total: 'TotalCount' 
       }, 
       complete: function (jqXHR, textStatus) { 
        //  HidePageLoader(); 

       }, 
       pageSize: 5, 
       serverPaging: true, 
       serverSorting: true, 
       serverFiltering: true, 
       columnMenu: true 
      }, 
      height: 300, 
      groupable: false, 
      sortable: true, 
      filterable: true, 
      pageable: { 
       refresh: true, 
       pageSizes: 5000 
      }, 
      columns: [{ template: '<input type="checkbox" id="#=Id#" class="gridCK" />', width: "35px" }, 
         { field: "Description", title: "Actions" }, ] 



     }); 

     var df = list; 
     var grid = $("#controllerGrid1").data("kendoGrid"); 
     grid.tbody.find("input").closest("tr").each(function (index, row) { 

      var dataItem = grid.dataItem(row); 
      for (var i = 0; i < df.length; i++) 
      { 

       if (df[i] == dataItem.Id) { 

        $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked"); 


     }); 


    } 

可以任何一個解釋我做錯了什麼?並建議是否有其他方法來做到這一點。在此先感謝

回答

1

我找到了一個解決方案。

var selected = $("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.uid + "]"); 
         selected 
         .find("td:first input") 
         .attr("checked", true); 

它添加上面的代碼,而不是按照後對我的作品,

$("#controllerGrid1 tbody").find("tr[data-uid=" + dataItem.Id + "]").attr("checked"); 
+0

簡化您的選擇:'$( 「#controllerGrid1 TBODY TR [數據的uid =」 + dataItem.uid +「] td:first input「)。attr(」checked「,true);'。不需要那麼多的「發現」...... – DontVoteMeDown