[转载]jQuery EasyUI DWR Loader

[转载]DWR Loader – Extension – jQuery EasyUI.

Include ‘dwrloader.js’

To using DWR to get data for easyui, include ‘dwrloader.js’ file first.

  1. <script type=“text/JavaScript src=“../../JQuery-1.7.2.min.js”></script>  
  2. <script type=“text/JavaScript src=“../../JQuery.easyui.min.js”></script>  
  3. <script type=“text/JavaScript src=“dwrloader.js”></script>  

Assign DWR method to ‘url’ property

As the default json loader, the ‘url’ property indicate the remote URL to retrieve json data. While using DWR loader, we should assign a function to ‘url’ property to retrieve data from DWR. Below is the example that show how to display a datagrid by using dwr loader:

  1. <table id=“dg”></table>  
  2. $(function(){  
  3.     $(‘#dg’).datagrid({  
  4.         columns: [[  
  5.             {field:“id”,title:‘ID’,width:80},  
  6.             {field:“text”,title:‘Text’,width:100}  
  7.         ]],  
  8.         singleSelect: true,  
  9.         autoRowHeight: false,  
  10.         width: 200,  
  11.         height: 200,  
  12.         url: MyTest.getDataGridData  
  13.     });  
  14. });  

The Java test code

  1. public class Test {  
  2.     public List<Map<String,Object>> getDataGridData(){  
  3.         List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();  
  4.         Map<String,Object> item = new HashMap<String,Object>();  
  5.         item.put(“id”, 1);  
  6.         item.put(“text”“text1”);  
  7.         items.add(item);  
  8.         item = new HashMap<String,Object>();  
  9.         item.put(“id”, 2);  
  10.         item.put(“text”“text2”);  
  11.         items.add(item);  
  12.         return items;  
  13.     }  
  14. }  

Download the EasyUI Extension:

jquery-easyui-dwrloader.zip
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏