JqueryEasyUI datagrid通過struts請求從後台讀取資料

來源:互聯網
上載者:User

標籤:jqueryeasyui   datagrid   

我就說下需要注意的事項,希望能協助到大家:1.後台返回的格式必須是JqueryEasyUI那種格式。比如:{"total":2,"rows":[{...}]"}這種形式。2.struts設定檔無須配置result,直接簡單配置就行,如下:        <!-- 使用者列表-->        <action name="userList" method="userList" class="com.duosen.ocs.system.action.UserAction">        </action>  
3.action中方法這麼寫,直接返回success:            result = userService.findPageUserList(this.getPage(), this.getLimit(), user);              //{total=2, rows=[[email protected], [email protected]]}
            JSONObject object = JSONObject.fromObject(result);                        HttpServletResponse response = ServletActionContext.getResponse();            response.setContentType("html/text;charset=UTF-8");            response.getWriter().write(object.toString());  
            return null;  
這樣前台返回資料格式為:


前台展現:


附上使用者管理jsp代碼:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/include.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<h2>CRUD DataGrid</h2>
<p>Double click the row to begin editing.</p>
<table id="dg" title="My Users" style="width:700px;height:250px"
toolbar="#toolbar" pagination="true" idField="id"
rownumbers="true" fitColumns="true" singleSelect="true">
<thead>
<tr>
<th field="loginname" width="50" editor="{type:‘validatebox‘,options:{required:true}}">使用者名稱</th>
<th field="password" width="50" editor="{type:‘validatebox‘,options:{required:true}}">密碼</th>
<th field="mobile" width="50" editor="text">電話</th>
<th field="createtime" width="50" editor="{type:‘validatebox‘,options:{validType:‘email‘}}">建立時間</th>
</tr>
</thead>
</table>
<div id="toolbar">
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="javascript:$(‘#dg‘).edatagrid(‘addRow‘)">New</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="javascript:$(‘#dg‘).edatagrid(‘destroyRow‘)">Destroy</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:$(‘#dg‘).edatagrid(‘saveRow‘)">Save</a>
<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="javascript:$(‘#dg‘).edatagrid(‘cancelRow‘)">Cancel</a>
</div>
<script type="text/javascript">
$(function(){
    $(‘#dg‘).edatagrid({
        url: window.BIZCTX_PATH + ‘/system/userjson/userList.action‘,
        saveUrl: ‘save_user.php‘,
        updateUrl: ‘update_user.php‘,
        destroyUrl: ‘destroy_user.php‘
    });
});
</script>
</body>
</html>


include.jsp的代碼:
<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ page import="com.duosen.ocs.constant.WebConstants" %>
<%@ page import="com.duosen.ocs.system.domain.User" %>
 
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    
%>

<script type="text/javascript">
        window.BIZCTX_PATH = "<%=path%>";
        var bizctxpath = "<%=path%>";
</script>


    <link rel="stylesheet" type="text/css" href="<%=path%>/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="<%=path%>/easyui/demo/demo.css">
    <script type="text/javascript" src="<%=path%>/easyui/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
    <script type="text/javascript" src="<%=path%>/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=path%>/resource/js/fmscookie.js"></script>
    <script type="text/javascript" src="<%=path%>/easyui/jquery.edatagrid.js"></script>

以上js都是jqueryEasyUi官方下載。

JqueryEasyUI datagrid通過struts請求從後台讀取資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.