juery easyui 前后台交互小demo[附源码]

一、

二、源码

1、java后台代码-------------用于生成一组数据传到前台页面

 private JSONObject resultObj;      //json-lib.jar包中自带的对象和方法,方便转换成传输的json类型数据

 @SuppressWarnings("unchecked")
 @Override
 public String execute() throws Exception {
  // TODO Auto-generated method stub
  Map map = new HashMap();
     ArrayList al = new ArrayList();
     for(int i=0;i<50;i++)
     {
      Map m = new HashMap();
      m.put("itemid", String.valueOf(i));
      m.put("mction", "a"); 
      al.add(m);
     }
     map.put("total", 50);
     map.put("rows", al);
     resultObj=JSONObject.fromObject(map);         //将map对象转换成为json对象
     return "success";
 }

 

2、jsp页面代码

<body οnlοad="fm()">
<s:debug></s:debug>

<table id="tt" border="1"></table>    //放置表格的容器

</body>

 

3、js代码

 $('#tt').datagrid({  
  
url:'msg.action',                            //url----指向struts中配置的action
   title:'demo',
 iconCls:'icon-save',
 width:600,
 height:350,
 nowrap: false,
 striped: true,
 collapsible:true,
 sortName: 'code',
 sortOrder: 'desc',
 remoteSort: false,
 idField:'code',
    columns:[[                                  //列field
       {field:'ck',checkbox:true},
          {field:'mction',title:'mction',width:100},  
          {field:'itemid',title:'itemid',width:100}
   ]] ,
   pagination:true,
   pageSize:20,
   pageNumber:1,
    rownumbers:true,
    toolbar:[{
     id:'btnadd',
     text:'Add',
     iconCls:'icon-add',
     handler:function(){
      $('#btnsave').linkbutton('enable');
      insertRow();
      //appendRow("b","555");
      //alert('add')
     }
    },{
     id:'btncut',
     text:'Cut',
     iconCls:'icon-cut',
     handler:function(){
      $('#btnsave').linkbutton('enable');
      alert('cut')
     }
    },'-',{
     id:'btnsave',
     text:'Save',
     disabled:true,
     iconCls:'icon-save',
     handler:function(){
      $('#btnsave').linkbutton('disable');
      alert('save')
     }
    }],
 
onClickRow:function(index,row){                  //一些事件编写
alert(index+"****"+row.itemid);
}

  });

4、struts配置文件------------关键

 <package name="json" namespace="/jsp" extends="json-default">
  <action name="msg" class="com.struts.action.FindMsg">
   <result type="json" >
    <param name="root">resultObj</param>
   </result>
  </action>
 </package>

5、文件目录树

6、源码

下载地址:http://download.csdn.net/detail/yixi524/4463584

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值