0

jqGrid 一直在踢我的屁股(以及本网站上的其他人)。使用 addJSONData 方法时,我似乎无法从 web 服务获取 JSON 数据以加载到 jqGrid 中。

有谁知道这是否可行?我不使用 MVC,只是在 ASP.NET 3.5 中使用普通的 WebProject Web 服务。

我正在使用最新版本的 jqGrid 3.5。

我不知道该怎么办。我目前正在尝试仅加载 1 行,我在我的 WS 中返回一个字符串,如下所示:

"Page:1,Total:1,Records:1,Rows:[name: Jeff V title: Programmer]"

然后将其传递到我的javascript中: {"d":"Page:1,Total:1,Records:1,Rows:[name: Jeff Vaccaro title: Programmer]"}

我的 jQuery 代码如下:

    jQuery(document).ready(function () {
    jQuery("#list").jqGrid({
        datatype: processrequest,
        mtype: 'POST',
        colNames: ['Name', 'Title'],
        colModel: [
      { name: 'name', index: 'name', width: 55 },
      { name: 'title', index: 'title', width: 90 }
      ],
        pager: jQuery('#pager'),
        rowNum: 10,
        rowList: [10, 20, 30],
        sortname: 'id',
        sortorder: "desc",
        viewrecords: true,
        imgpath: 'themes/basic/images',
        caption: 'My first grid'
    });
});


function processrequest(postdata) {
    $(".loading").show();
    $.ajax({
        type: "POST",
        data: "{}",
        datatype: "clientside",
        url: "../webServices/myTestWS.asmx/testMethod",
        contentType: "application/json; charset-utf-8",
        complete: function (jsondata, stat) {
            if (stat == "success") {
                jQuery("#list")[0].addJSONData(eval("(" + jsondata.responseText + ")"));
                $(".loading").hide();
            } else {
                $(".loading").hide();
                alert("Error with AJAX callback");
            }
        }
    });
}

我已经尝试了 addJSONData 代码的各种不同变体。有谁知道这是否可行?

任何帮助表示赞赏!

谢谢

4

1 回答 1

3

首先,您的 Web 服务应该返回一个具有属性pagetotalrecords等的类实例rows。如果 web 方法具有属性[ScriptMethod (ResponseFormat = ResponseFormat.Json)],则类实例将正确转换为 JSON 数据。

您可以使用ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }参数和jsonReader(参见http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data)在 jqGrid 中加载数据。来自Jqgrid 3.7 的信息不会在 Internet Explorer 中显示行,传递给 Web 服务之前将 jqGrid rowNum 从 ALL 更改为 -1 的最佳方法可能对您有所帮助。

最后imgpath,jqGrid 3.5 版不再支持。

于 2010-06-30T17:56:22.740 回答