首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >P是未定义的jqgrid

P是未定义的jqgrid
EN

Stack Overflow用户
提问于 2012-03-05 20:43:57
回答 1查看 3.7K关注 0票数 0

我有个有趣的问题。我已经用多个网格在多个页面上完成了这个任务。第一个网格运行良好,第二个网格在这种情况下无法加载。并给出以下错误:

P是未定义的

...sArray(i)){P=true;h="last";U=f}else{i=i;P=false}this.each(function(){var D=i.l..。第140行jquery.jqGrid.min.js

用户doble单击一行,这将设置一些变量,然后调用函数locationGrid()。

就像我说的,这在过去已经对我起过多次作用,但是在这个页面上它失败了。我已经进行了二次检查,并且正在获取数据,如下所示:

{“d”:“{\”总\“:1,\”页\“:0,\”记录\“:1,\”行\“:{\”invPartLocId\“:1053,\”库存“deptCode\”5,\“位置\”空“,\”itemType\“:\”S“,\"currentQanity\":1,\”佐剂质量“:0,\”newLocationQty“:0,\"deptCode\":\"1401 }”}

任何帮助都将不胜感激。

代码语言:javascript
复制
    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]);


            }
    }
EN

回答 1

Stack Overflow用户

发布于 2012-03-06 14:20:54

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

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

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

在进行了最小的更改之后,演示就可以工作了。我只评论了使用HTTP的"POST“,因为我直接从文件中获得JSON,并且在wed服务器上没有活动组件。

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

代码语言:javascript
复制
{
    "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。修改后的代码可以有以下内容:

代码语言:javascript
复制
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);
    }
});

下一个演示展示了代码的工作原理。我在演示中包括了loadonce: true选项,它也会对您有所帮助。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9573699

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档