1、傳統方式
1 $(function () { 2 var url = "../Source/Query/jhDataQry.ashx?action=query"; 3 $(dg).datagrid({ 4 url: url, 5 queryParams: { 6 qsrq: qsrq, 7 zzrq: zzrq 8 } 9 }); 10 }) 11 12 <table id="DataGrid" class="easyui-datagrid" fit="true" border="false" toolbar="#TBar" pagination="true" 13 data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh', queryParams: { 'action': 'query'}" 14 rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx"> 15 <thead> 16 <tr> 17 </tr> 18 </thead> 19 </table>
2、原因分析及解決方案
html代碼中利用class聲明了datagrid,導致easyUI解析class代碼的時候先解析class聲明中的datagrid,這樣組件就請求了一次url;然后又調用js初始化代碼請求一次url。這樣導致了重復加載,解決的方法就是只用一種初始化方法來聲明easyUI組件以避免重復的提交請求,即刪除html中的class聲明(class="easyui-datagrid"),修改后的代碼如下:
1 <table id="DataGrid" fit="true" border="false" toolbar="#TBar" pagination="true" 2 13 data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh'" 3 14 rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx"> 4 15 <thead> 5 16 <tr> 6 17 </tr> 7 18 </thead> 8 19 </table>