时间:2021-07-30 08:13:59 | 栏目:jquery | 点击:次
jQuery 开发之EasyUI 添加数据的实例
1、创建toolbar:
toolbar:[{ text:'增加', iconCls:'icon-add', handler:function(){ openAddUserDialog(); } }]
2、添加dialog,里面有添加用户的表单
<div id="addDialog" 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 }); }}); } }]" class="easyui-dialog"> <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; } }
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!