javascript - 未捕获的类型错误 : Cannot read property 'data' of undefined jquery Jtable

标签 javascript jquery asp.net-mvc jquery-ui jquery-jtable

我已经调查这个问题超过 12 个小时,但没有找到任何解决方案。我对 jtable 有很好的了解,并且已经使用它很长时间了。我有一个普通的 div,我想使用 jtable 构建它,因此我从应用程序中的旧工作示例复制了代码并对其进行了编辑,但是控制台中出现了一个 javascript 错误,该错误阻止了数据显示在表中:

Uncaught TypeError: Cannot read property 'data' of undefined jquery Jtable

这是我的 html 页面:

@model Tuple<List<SIO.Core.Entities.Group>, List<SIO.Core.Entities.WorkFlow>>
@section JavaScript
{

<script type="text/javascript" src="@Url.Content("/Scripts/GroupHandler.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/jquery-ui.js")"></script>
<script type="text/javascript"      src="@Url.Content("/Scripts/jquery.jtable.js")"></script>

}


@{
ViewBag.Title = "المجموعات";
Layout = "~/Views/Shared/_Layout.cshtml";
}



<div id="divBackgroundtask" style="display: none;">
</div>
<div id="indx_divtask">
    <section class="col-md-8 taskPoolfilterSection">

    <div class="form-group">
        <div class="border-top">
        </div>
        <div id="filter" class="panel-body margin-bottom">
            <header class="panel-heading containt-border">
                @ViewBag.Title
            </header>
        </div>


    </div>

    <!-- /.panel-body -->


    <div id="divPleaseWaittask" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="load_div col-sm-offset-2 col-sm-5">
            <div class="  row col-sm-2 col-sm-offset-9">
                <img src="~/Images/Loading.gif" />
            </div>

            <div class="row col-sm-12 txt_wait">
                <b>برجاء الإنتظار حتى إكمال العملية</b>
            </div>
        </div>

    </div>



</section>

<div id="GroupsContainer" class="table-responsive">

</div>

这是我构建 jtable 的 javascript 代码:

(document).ready(function () {
    $('#GroupsContainer').jtable({
        paging: true,
        sorting: true,
        messages: {
            close: 'اغلاق',
            pagingInfo: 'عرض {0}-{1} من {2}',
            pageSizeChangeLabel: 'تعداد الصف',
            noDataAvailable: 'لا يوجد بيانات للعرض!',
            gotoPageLabel: 'الذهاب الى صفحة',
            serverCommunicationError: 'حدث خطأ ما اثناء الإتصال...',
        },

        actions: {
            //listAction: '/TaskPool/GetTasks?isAdmin=' + IsAdmin,
            listAction: function (postData, jtParams) {
                // alert("Loading...");
                PleaseWaitDialogtask.show(true);
                return $.Deferred(function ($dfd) {
                    $.ajax({
                        url: '/Group/GetAllGroups?' + 'jtStartIndex=' + jtParams.jtStartIndex + '&jtPageSize=' + jtParams.jtPageSize + '&jtSorting=' + jtParams.jtSorting,
                        type: 'Get',
                        dataType: 'json',
                        data: postData,
                        success: function (data) {
                            $dfd.resolve(data);
                            PleaseWaitDialogtask.show(false);
                        },
                        error: function () {
                            $dfd.reject();
                        }
                    });
                });
            },
        },
        fields: {
            ID: {
                key: true,
                list: false
            },
            GroupName: {
                title: 'اسم المجموعة'//,
                //width: '40%'
            },
            GroupDisc: {
                title: 'وصف المجموعة'//,
                //width: '40%'
            },

            Link: {
                title: '',
                display: function (data) {
                    if (data.isRedirect) {
                        window.location.href = data.redirectUrl;
                    }
                }
            },
        }

    });
    $('#GroupsContainer').jtable('load');
    $('.jtable')[0].className = $('.jtable')[0].className + " table table-striped table-bordered table-hover";
});

这是导致错误的行:

 $dfd.resolve(data);

这是我检索记录的操作方法:

[HttpGet]
        public JsonResult GetAllGroups(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null, string rangeSt = "", string rangeEd = "")
        {
            try
            {
                LogHelpper.LogMessage("GroupContorller GetAllSystemUsers Post Method Started", EventLogEntryType.Information, log);

                GroupManager groupManager = new GroupManager();
                List<Group> groups = groupManager.SkipAndTake(jtStartIndex, jtPageSize);
                List<GroupCustomViewModel> groupCustomViewModel = groups.Select(group => new GroupCustomViewModel(group)).ToList();

                LogHelpper.LogMessage("GroupContorller GetAllGroups Post Method Ended", EventLogEntryType.Information, log);





                return Json(new { Result = "OK", Records = groupCustomViewModel , TotalRecordCount = groupCustomViewModel .Count }, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                LogHelpper.LogMessage("Error Message", EventLogEntryType.Error, log);
                LogHelpper.LogException(ex, EventLogEntryType.Error, log);
                return Json(new { Result = "ERROR", Message = ex.Message }, JsonRequestBehavior.AllowGet);
            }
        }

这是我的模型:

public class GroupCustomViewModel
    {
        #region properties
        /// <summary>
        /// Gets or sets the GoupIDPK.
        /// </summary>
        /// <value>The GoupIDPK.</value>
        public int GoupIDPK { get; set; }
        /// <summary>
        /// Gets or sets the GroupName.
        /// </summary>
        /// <value>The GroupName.</value>

        public string GroupName { get; set; }
        /// <summary>
        /// Gets or sets the GroupDisc.
        /// </summary>
        /// <value>The GroupDisc.</value>
        public string GroupDisc { get; set; }

        public string EditHyperlink { get; set; }

        public string DeleteHyperlink { get; set; }

        public string DetalisHyperlink { get; set; }

        public bool DefaultGroup { get; set; }
        #endregion
    }

抱歉,如果问题太长,但我不知道错误在哪里,所以我 发布了完成该任务所需的所有代码。

最佳答案

终于找到问题所在了!! ...在字段部分ID的jTable定义中,但模型字段名称是GroupIDPK,因此将jTable字段ID更改为GroupIDPK解决了问题

关于javascript - 未捕获的类型错误 : Cannot read property 'data' of undefined jquery Jtable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38134941/

相关文章:

javascript - 当第一个初始元素没有与此 jquery 等效的某个类 CSS 时,选择下一个元素

javascript - 从加载的 KML 向标记添加点击事件

javascript - 空间复杂度 js 函数

javascript - 单击其他元素时打开页脚元素

javascript - 图像作为较小的图像位

asp.net-mvc - ASP.NET MVC : get "Main-Controller" in RenderAction

javascript - 在 JavaScript 中获取图像数据 URL?

当我检查它时,jQuery 复选框没有响应

jquery - 有没有办法优化 chrome 的视差滚动?

javascript - 为什么不需要等待数据库查询的返回