jQuery 开发之EasyUI 添加数据的实例

jQuery 开发之EasyUI 添加数据的实例

1、创建toolbar:

toolbar:[{ text:'增加', iconCls:'icon-add', handler:function(){ openAddUserDialog(); } }]

2、添加dialog,里面有添加用户的表单

<div data-options="closed:true,modal:true,title:'addUser', buttons:[{ text:'保存', iconCls:'icon-add', handler:function(){ //addUser(); $('#addForm').form('submit',{url:'${rootPath}/user_add.action',success:function(data){ var result = JQuery.parseJSON(data); if(result.success){ //$("#datagrid").datagrid('reload'); $("#addDialog").dialog('close'); //把插入的数据添加到最后一行 //$("#datagrid").datagrid('appenRow',result.obj); $("#datagrid").datagrid('insertRow',{ index:0; row:result.obj//obj里面存了user对象 }); } $.message.show({ title:'提示', msg:obj.msg }); }}); } }]"> <table> <tr> <th></th> <tr/> </table> </div>

3、打开对话框:

function openAddUserDialog(){ $(“#addDialog").dialog('open'); }

4、服务器端返回的json

//返回的json public class Json implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; private boolean success = false; private String msg = ""; private Object obj = null; public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public Object getObj() { return obj; } public void setObj(Object obj) { this.obj = obj; } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyzgpd.html