2011-12-06 95 views

回答

1

您可以定义一个变量,它持有JSON响应的最后状态从服务器返回:

var serverData; 
$('#list').jqGrid({ 
    datatype: 'json', 
    // ... other parameters 
    loadComplete: function (data) { 
     serverData = data; // or serverData = data.rows 
     // ... 
    }, 
    onSelectRow: function (id) { 
     if (serverData) { 
      // here you can access serverData, but you need 
      // here probably find the item in the serverData 
      // which corresponds the id 
     } 
    } 
}); 

如果从形式

{ 
    "total": "xxx", 
    "page": "yyy", 
    "records": "zzz", 
    "rows" : [ 
    {"id" :"1", "cell": ["cell11", "cell12", "cell13"]}, 
    {"id" :"2", "cell": ["cell21", "cell22", "cell23"]}, 
     ... 
    ] 
} 

有例如JSON数据那么你可以直接保存在serverData不是数据。这可能是有趣的,只保存cell部分并将其保存为serverData[id]值:

var serverData = []; 

$('#list').jqGrid({ 
    datatype: 'json', 
    // ... other parameters 
    loadComplete: function (data) { 
     var i, rows = data.rows, l = rows.length, item; 
     for (i = 0; i < l; i++) { 
      item = rows[i]; 
      serverData[item.id] = item.cell; 
     } 
     // ... 
    }, 
    onSelectRow: function (id) { 
     var item = serverData[id]; // the part of data which we need 
    } 
}); 

如果使用repeatitems: false设置在jsonReader那么您可以在项目的serverData只有部分保存(所选属性)代表了服务器数据的行。

以任何方式,你应该在一些变量定义loadCompleteloadCompletedata参数保存的信息的一部分。

+0

你可以看看这个吗? http://stackoverflow.com/questions/8564806/jqgrid-error-when-moving-from-1-page-to-another – techlead

相关问题