本人剛剛開始使用jqGrid。我試圖做一個通用的函數,我可以調用加載一個jqGrid與不同的postData參數,在函數調用中定義。發送數組作爲postData參數
有沒有辦法做到這一點?我曾考慮創建一個數組來存儲參數的名稱/值,然後將其設置爲postData中的參數。然後Web服務將通過並將這些參數添加到SQL存儲過程調用中。
這裏是通用代碼:
var paramArray = new Array();
var p1 = new JQGridParam("CustomerName","John");
var p2 = new JQGridParam("ProductName","Kleenex");
var p3 = new JQGridParam("YearPurchased","2012");
paramArray[0] = p1;
paramArray[1] = p2;
paramArray[2] = p3;
$("#list").jqGrid({
datatype: "json",
url: "services/Customers.asmx/GetCustomerData",
mtype: "POST",
postData: {
sqlParams: paramArray //HERE IS WHERE I NEED THE HELP
},
ajaxGridOptions: { contentType: "application/json; charset=utf-8" },
ajaxRowOptions: { contentType: "application/json; charset=utf-8" },
serializeGridData: function (postData) {
return JSON.stringify(postData);
},
serializeRowData: function (postData) {
return JSON.stringify(postData);
},
jsonReader: {
root: function (obj) { return obj.d.rows; },
page: function (obj) { return obj.d.page; },
total: function (obj) { return obj.d.total; },
records: function (obj) { return obj.d.records; },
},
colModel: [
{name: "CustID", index: "CustID" },
{name: "PurchaseAmount", index: "PurchaseAmount" }],
colNames: ["Customer ID", "Amount Purchased"],
pager: $("#pager"),
loadOnce: true,
rowNum: 10,
rowList: [10,25,50],
gridview: true,
viewrecords: true
});
當我嘗試這一點,它拋出錯誤「不能轉換System.String類型的對象輸入的System.Array」。任何人有任何想法如何去做這件事?
你可以請發表代碼鑄造回對象?或者至少回到陣列。謝謝。 – CodeLover 2016-05-20 11:30:09