this.p是未定义的jqgrid

时间:2012-03-05 20:43:57

标签: jqgrid

我有一个有趣的问题。我在多个网格上完成了这个。第一个网格工作正常,第二个网格在这种情况下无法加载。并给出以下错误:

this.p未定义

... sArray(i)){P = true; h =“last”; U = f} else {i = [i]; P = false} this.each(function(){var D = il ..第140行jquery.jqGrid.min.js

用户点击一行并设置一些变量,然后调用函数locationGrid()。

就像我说的那样,过去曾多次为我工作,但是在这个页面上它失败了。我已经进行了双重检查,我将获得数据,如下所示:

{ “d”: “{\” 总\ “:1,\” 页面\ “:0,\” 记载\ “:1,\” 行\ “:[{\” invPartLocId \“:1053, \ “inventoryMasterId \”:5,\ “位置\”:空,\ “ITEMTYPE \”:\ “S \”,\ “currentQanity \”:1,\ “adjustedQauntity \”:0,\ “newLocationQty \”: 0,\“deptCode \”:\“1401 \”}]}“}

任何帮助都将不胜感激。

    function locationGrid() {
        $('#invLocAdjustGrid').jqgrid({
            height: 290,
            loadui: "block",
            datatype: function (rdata) { getLocationData(rdata); },
            colNames: ['invPartID', 'locationPartID', 'Loctaion', 'Type', 'Current QTY', 'Adjusted QTY', 'New Location QTY', 'Dept. Code'],
            colModel: [
                    { name: 'invPartLocId', width: 2, sortable: false, editable: false, hidden: true },
                    { name: 'inventoryMasterId', width: 2, sortable: false, editable: false, hidden: true },
                    { name: 'location', width: 250, editable: false, sortable: false },
                    { name: 'itemType', width: 120, editable: false, sortable: false, align: 'center' },
                    { name: 'currentQanity', width: 50, editable: false, sortable: false },
                    { name: 'adjustedQauntity', width: 50, editable: false, sortable: false },
                    { name: 'newLocationQty ', width: 50, editable: false, sortable: false },
                    { name: 'deptCode', width: 50, editable: false, sortable: false }
                ],
           pager: jQuery('#rptCodesPager'),
            viewrecords: true,
            width: 890,
            gridComplete: function () {
                $('#load_invLocAdjustGrid').hide();
                $(this).prop('p').loadui = 'enable';
                $('#lui_invLocAdjustGrid').hide();

            },
            afterInsertRow: function (rowid, aData) {

            },
            ondblClickRow: function (rowid) {
                var myID = $('#invLocAdjustGrid').getCell(rowid, 'invPartLocId');
                Ldclicked(myID);
            }
        });
    }
    function getLocationData(rdata) {
        var theID = tempID;
        tempID = "";
        var myDTO = { 'id': theID };
        var toPass = JSON.stringify(myDTO);
        $.ajax({
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            url: "INV_Inventory_Adjustment.aspx/getInventoryLocationById",
            data: toPass,
            success: function (data, textStatus) {
                if (textStatus == "success")
                    ReceivedLocationData(JSON.parse(getMain(data)).rows);
            },
            error: function (data, textStatus) { alert('An error has occured retrieving data!'); }
        });
    }
    function ReceivedLocationData(data) {
        var thegrid = $('#invLocAdjustGrid');
        var isGood = data.length;
        for (var i = 0; i < isGood; i++) {
                thegrid.addRowData(i + 1, data[i]);


            }
    }

1 个答案:

答案 0 :(得分:4)

抱歉,您的代码有问题。此外,我建议你重写整个代码,我试着解释原因。

第一个重要错误是您在$('#invLocAdjustGrid').jqgrid({...});而不是locationGrid中使用$('#invLocAdjustGrid').jqGrid({...});。 JavaScript区分大小写,因此使用jqGrid代替jqgrid非常重要。

存在下一个问题是因为您使用了一些未在发布的代码中定义的变量和函数tempIDLdclickedgetMain

进行最小的更改后the demo有效。我只评论&#34; POST&#34;使用HTTP GET,因为我直接从文件中获取JSON并且在服务器上没有活动组件。

您清楚的另一个问题是您的服务器代码序列化结果两次。通常由于ASMX WebMethods的错误使用而出现问题。应该手动将对象转换为JSON。而不是那个只需要返回对象本身。由于这个问题,JSON的d属性不是对象本身,而是一个字符串,应该再解析一次:

{
    "d": "{\"total\":1,\"page\":0,\"records\":1,\"rows\":[{\"invPartLocId\":1053,\"inventoryMasterId\":5,\"location\":null,\"itemType\":\"S\",\"currentQanity\":1,\"adjustedQauntity\":0,\"newLocationQty\":0,\"deptCode\":\"1401 \"}]}"
}

即使这样的错误格式化数据也可以通过jqGrid 读取而不使用用法datatype作为函数。此外,您应始终使用gridview: true,绝不使用afterInsertRow,几乎不使用addRowData。修改后的代码可以是以下内容:

var tempID = "abc";
$('#invLocAdjustGrid').jqGrid({
    url: "INV_Inventory_Adjustment.aspx/getInventoryLocationById",
    mtype: "POST",
    datatype: "json",
    postData: {
        id: function () { return tempID; } // ??? I don't know which data should be send
    },
    ajaxGridOptions: { contentType: "application/json" },
    serializeRowData: function (data) {
        return JSON.stringify(data);
    },
    beforeProcessing: function (data) {
        $.extend (true, data, $.parseJSON(data.d));
    },
    jsonReader: {repeatitems: false},
    loadonce: true,
    colNames: ['invPartID', 'locationPartID', 'Loctaion', 'Type', 'Current QTY', 'Adjusted QTY', 'New Location QTY', 'Dept. Code'],
    colModel: [
        { name: 'invPartLocId', width: 2, key: true, hidden: true },
        { name: 'inventoryMasterId', width: 2, hidden: true },
        { name: 'location', width: 250 },
        { name: 'itemType', width: 120, align: 'center' },
        { name: 'currentQanity' },
        { name: 'adjustedQauntity' },
        { name: 'newLocationQty ' },
        { name: 'deptCode' }
    ],
    cmTemplate: {sortable: false, width: 50},
    pager: '#rptCodesPager',
    viewrecords: true,
    gridview: true,
    loadui: "block",
    height: 290,
    width: 890,
    ondblClickRow: function (rowid) {
        //Ldclicked(rowid);
    }
});

The next demo证明代码有效。我在演示中添加了loadonce: true选项,这对您也很有帮助。

相关问题