2012-03-05 207 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