[转载]DWR Loader – Extension – jQuery EasyUI.
Include ‘dwrloader.js’
To using DWR to get data for easyui, include ‘dwrloader.js’ file first.
- <script type=“text/JavaScript” src=“../../JQuery-1.7.2.min.js”></script>
- <script type=“text/JavaScript” src=“../../JQuery.easyui.min.js”></script>
- <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:
- <table id=“dg”></table>
- $(function(){
- $(‘#dg’).datagrid({
- columns: [[
- {field:“id”,title:‘ID’,width:80},
- {field:“text”,title:‘Text’,width:100}
- ]],
- singleSelect: true,
- autoRowHeight: false,
- width: 200,
- height: 200,
- url: MyTest.getDataGridData
- });
- });
The Java test code
- public class Test {
- public List<Map<String,Object>> getDataGridData(){
- List<Map<String,Object>> items = new ArrayList<Map<String,Object>>();
- Map<String,Object> item = new HashMap<String,Object>();
- item.put(“id”, 1);
- item.put(“text”, “text1”);
- items.add(item);
- item = new HashMap<String,Object>();
- item.put(“id”, 2);
- item.put(“text”, “text2”);
- items.add(item);
- return items;
- }
- }