2013-05-08 49 views
0

第一個表上的選擇會導致第二個表中的更改。但是,更改只發生一次。任何後續調用都會生成有效的JSON,但html保持不變。MVC 4,j表2.3在第二次(+)調用時不重建表數據

控制器:

[HttpPost] 
    public JsonResult M1List(int jtStartIndex, int jtPageSize, string jtSorting) 
    { 
     try 
     { 
      List<tblM> m1 = new DataHelper().GetM1(jtSorting, jtPageSize, jtStartIndex); 
      int m1Count = new DataHelper().Getm1Count(); 

      return Json(new { Result = "OK", Records = m1, TotalRecordCount = m1Count }); 
     } 
     catch (Exception ex) 
     { 
      return Json(new { Result = "ERROR", Message = ex.Message }); 
     } 
    } 

    [HttpPost] 
    public JsonResult M2List(int mId, int jtStartIndex, int jtPageSize) 
    { 
     try 
     { 
      List<ViewM1A> m2 = new DataHelper().GetM2ForM1(mId.ToString(), "mId", jtPageSize, jtStartIndex); 
      int m2Count = new DataHelper().GetM2ForM1Count(mId.ToString()); 

      return Json(new { Result = "OK", Records = m2, TotalRecordCount = m2Count }); 
     } 
     catch (Exception ex) 
     { 
      return Json(new { Result = "ERROR", Message = ex.Message }); 
     } 
    } 

的JS:

$(document).ready(function() { 
    $('#m1TC').jtable({ 
     paging: true, 
     sorting: true, 
     defaultSorting: 'Name ASC', 
     selecting: true, //Enable selecting 
     multiselect: false, //Allow multiple selecting 
     actions: { 
      listAction: '@Url.Action("M1List")' 
     }, 
     fields: { 
      mId: { 
       title: 'Id' 
      } 
     }, 
     selectionChanged: function() { 
      var $selectedRows = $('#m1TC').jtable('selectedRows'); 
      $selectedRows.each(function() { 
       var record = $(this).data('record'); 
       buildM2Table(record.mId); 
      }); 
      $('#m2TC').jtable('load'); 
     } 
    }); 
    $('#m1TC').jtable('load'); 
}); 

function buildM2Table(actionUrl) { 
    $('#m2TC').jtable({ 
     paging: true, 
     sorting: true, 
     defaultSorting: 'Name ASC', 
     selecting: true, //Enable selecting 
     multiselect: true, //Allow multiple selecting 
     selectingCheckboxes: true, //Show checkboxes on first column 
     actions: { 
      listAction: '/Connections/M2List?mId=' + actionUrl 
     }, 
     fields: { 
      FullName: { 
       title: 'Name' 
      }, 

     }, 
     selectionChanged: function() { 
      var $selectedRows = $('#m2TC').jtable('selectedRows'); 

      $('#SelectedRowList').empty(); 
      if ($selectedRows.length > 0) { 
      } else { 
       $('#SelectedRowList').append('No row selected! Select rows to see here...'); 
      } 
     } 
    }); 
} 

在HTML:

<div id="m1TC"></div> 
<div id="m2TC"></div> 

回答

0

通過後「記錄變種= $(本)。數據添加此代碼解決(「記錄」);':

$('#m2TC').remove(); 
$('#m1TC').after('<div id="m2TC"></div>'); 
相關問題