2012-03-05 108 views
0

我有一个有趣的问题。我在多个网格上完成了这个工作。在这种情况下,第一个网格工作正常,第二个网格未能加载。并提供以下错误:this.p is undefined jqgrid

this.p未定义

... sArray(ⅰ)){P =真; H = “最后”; U = F}否则{I = [I]; P = false} this.each(function(){var D = il .. line 140 jquery.jqGrid.min.js

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

就像我说这对我多次在过去的工作,但是这个网页它失败的我有双重检查,按照下图我得到的数据备份:。

{“d”:“{\”total \“:1,\”page \“:0,\”records \“:1,\”rows \“:[{\”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]); 


      } 
    } 
+2

您应该使用'jquery.jqGrid.src.js'而不是'jquery.jqGrid.min.js'来查看错误更清楚的地方。此外,你应该包含调用'locationGrid'的代码。我认为有理解问题。'locationGrid'只能被调用** **一次**。 – Oleg 2012-03-05 20:49:59

+0

我切换到使用jquery.jqGrid.src.js,失败是在2818行 ni = t.p.rownumbers === true? 1:0; – 2012-03-06 12:28:46

回答

4

对不起,但你的代码是越野车。此外,我建议您重写整个代码,并尝试解释原因。

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

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

作出最小改动the demo的作品。我仅评论“POST”使用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,这对您也有帮助。

+2

这样一个很好的答案,它没有被标记为正确的... – Javier 2014-02-15 18:25:45

+1

@Javier:谢谢! – Oleg 2014-02-15 18:42:23