【问题标题】:Firebug errors that I cannot make them disappear我无法让它们消失的 Firebug 错误
【发布时间】:2011-12-26 15:25:45
【问题描述】:

我在 Firebug 中不断收到此错误:
d is undefined [Break On This Error] randId:function(d){return(d?d:b.jgrid....(i,d);if(g)return d;return d.length>

我使用 JqGrid 版本:4.3.1

我的控制器方法如下所示:

public JsonResult CategoryList(int page)
    {
        List<CategoryDTO> categories = ServiceUtil.AuctionService.ListCategories();
        List<dynamic> json = new List<dynamic>();

        if (categories != null && categories.Count > 0)
        {
            foreach (CategoryDTO cat in categories)
            {
                json.Add(new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD });
            }
        }

        var result = new
        {
            total = 1,
            page = page,
            records = categories == null ? 0 : categories.Count,
            rows = (from cat in categories.Take(10)
                    select
                        new { Id = cat.Id, Name = cat.Name, Update = cat.LastUpdate, Regex = cat.ValidationXSD }
                    ).ToArray()
        };

        return Json(result, JsonRequestBehavior.AllowGet);

    }

这样的观点:

$(document).ready(function () {
    $("#jqgridListCategory").jqGrid({
        url: '/Admin/ManageCategory/CategoryList',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Id', 'Name', 'LastUpdate', 'RegularExpression'],
        colModel: [{ name: 'Id', index: 'Id', width: 40, align: 'left' }, { name: 'Name', index: 'Name', width: 400, align: 'left' }, { name: 'LastUpdate', index: 'LastUpdate', width: 40, align: 'left' }, { name: 'RegularExpression', index: 'RegularExpression', width: 40, align: 'left'}],
        pager: jQuery('#pager'),
        rowNum: 10,
        rowList: [5, 10, 20, 50],
        sortname: 'Id',
        sortorder: "desc",
        viewrecords: true,
        caption: 'Categories'
    });
}); 

我不知道出了什么问题,有什么想法吗?

编辑 1:使用最新的 jquery 版本 1.7.2。

编辑 2:我不希望控制器中的正则表达式在视图中只是一个字符串

【问题讨论】:

  • 尝试使用其他jquery版本
  • 你用json变量做什么?
  • 在你的控制器中你把Regex和javascript期望RegularExpression,对吗?
  • 我正在使用该变量从 jqgrid 返回所有数据

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


【解决方案1】:

CategoryList 操作以错误的格式生成数据。要么您必须使用jsonReader,要么更改CategoryList 操作的代码。

The standard format 来自服务器响应的 rows 部分的项目应如下所示

{"id" :"1", "cell": ["cell11", "cell12", "cell13"]}

如果第一列 Id 是唯一的并且可以用作行的 id,则可以只使用数组或字符串:

rows = (from cat in categories.Take(10)
        select new[] {
            cat.Id.ToString(),
            cat.Name,
            cat.LastUpdate.ToString(),
            cat.ValidationXSD
        }).ToArray()

在 jqGrid 中,您应该将 key: true 添加到“Id”列的属性列表中,并添加以下 jqGrid 选项

jsonReader: { cell: "" }

我建议您使用我的old answer 中的the demo projectanother answer 中的modification

【讨论】:

  • @Floradu88:不客气!在我在回答中建议的更改后,您在问题中描述的问题是否仍然存在?
  • 我必须做一些更改,以恢复我所做的一些更改,如果可行,将接受答案
  • @Floradu88:好的,如果你有任何问题,你可以在这里写评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多