【问题标题】:MVC 4, jTable 2.3, Table data isn't rebuilt on second (+) callMVC 4,jTable 2.3,表数据不会在第二次 (+) 调用时重建
【发布时间】:2013-05-08 15:09:50
【问题描述】:

对第一个表的选择会导致第二个表发生变化。但是,更改只发生一次。任何后续调用都会生成有效的 JSON,但 html 保持不变。

控制器:

[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>

【问题讨论】:

    标签: c# jquery asp.net-mvc jquery-ui jtable


    【解决方案1】:

    在 'var record = $(this).data("record");' 后面加上这段代码解决:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-31
      相关资源
      最近更新 更多