在您发布链接http://ccclients.com/TEST/TEST.php 后,我明白您犯了什么错误。您不应该在 两个 调用中分隔 jqGrid 定义:
jQuery("#list").jqGrid({
datatype: 'xml',
mtype: 'GET',
loadonce: true,
// other parameters
caption: 'My first grid',
xmlReader: {
root: "export",
row: "row",
repeatitems: false
}
});
和
$("#list").jqGrid({loadComplete:
function() {
alert('load complete')
}
});
但将loadComplete 定义为$("#list").jqGrid({ ... }); 的一个调用的一部分,如下所示:
jQuery("#list").jqGrid({
datatype: 'xml',
mtype: 'GET',
loadonce: true,
// other parameters
caption: 'My first grid',
xmlReader: {
root: "export",
row: "row",
repeatitems: false
},
loadComplete: function(data) {
alert('load complete');
}
});
如果您稍后必须设置事件处理程序,您应该使用setGridParam 方法(参见Add an event handler to jqGrid after instantiation)
此外,我完全不同意 Groxx 的回答。将为所有数据类型(包括“xml”、“json”、“local”等)调用函数loadComplete。如何在http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events#execution_order 下的文档中看到函数loadComplete 是在数据加载(或刷新)后在网格中进行一些修改的理想场所。我永久使用此功能。如果您需要加载非常奇特的数据(既不是 xml 也不是 json 等),则使用数据类型函数是最后一种方法。对于 xml 和 json 数据的加载,jqGrid 中有很多自定义功能(例如,参见 Setting the content-type of requests performed by jQuery jqGrid)。因此,您可以自定义jQurey.ajax 调用,并将用作jQurey.ajax 的输入和输出的数据转换为您想要的。