解决JQuery EasyUI 加载两次url的问题

来源:互联网 发布:网络管理基础知识 编辑:程序博客网 时间:2024/06/06 19:41

转自:http://www.cnblogs.com/easypass/archive/2012/12/16/2820996.html

1、传统方式

<span style="font-size:18px;">$(function () {            var url = "../Source/Query/jhDataQry.ashx?action=query";            $(dg).datagrid({                url: url,                queryParams: {                    qsrq: qsrq,                    zzrq: zzrq                }            });        }) <table id="DataGrid" class="easyui-datagrid" fit="true" border="false" toolbar="#TBar" pagination="true"           data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh', queryParams: { 'action': 'query'}"           rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx">          <thead>              <tr>            </tr>          </thead>      </table></span>

2、原因分析及解决方案

html代码中利用class声明了datagrid,导致easyUI解析class代码的时候先解析class声明中的datagrid,这样组件就请求了一次url;然后又调用js初始化代码请求一次url。这样导致了重复加载,解决的方法就是只用一种初始化方法来声明easyUI组件以避免重复的提交请求,即删除html中的class声明(class="easyui-datagrid"),修改后的代码如下:

<span style="font-size:18px;"><table id="DataGrid"  fit="true" border="false" toolbar="#TBar" pagination="true" data-options="pageSize:20,pageList: [10, 20, 30, 40, 50,100,5000],idField:'chjid',sortName:'chjbh'" rownumbers="true" singleSelect="true" url="../Source/JiChu/chjdoc.ashx">  <thead>  <tr></tr>  </thead>  </table></span>




0 0