jQuery EasyUI里表单(Form)的load方法实例。

jQuery EasyUI里表单(Form)的load的方法 需要返回什么格式的JSON文件 ,我的返回数据显示不了 有实例的大哥们。

[color=red]HTML:[/color]

    function editInfo(){
        var row = $('#test').datagrid('getSelected');
        if(row){
            win.window('open');
            var code = row.code;
            $('#form1').form('load', 'get.action?code='+code);
        }else{
            $.messager.alert('提示信息','请先选择要更新的记录。','info');
        }                     
    }

    <form method="post" id="form1"> 
        <table>
            <tr>
                <td>企业编号:</td>
                <td><input name="qybh" style="width:200px;"  id="qybh"></input></td>
            </tr>
            <tr>
                <td>企业名称:</td>
                <td><input name="qymc" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>设备序号 :</td>
                <td><input name="sbxh" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>设备名称:</td>
                <td><input name="sbmc" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>正常率:</td>
                <td><input name="zcl" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>保修率:</td>
                <td><input name="bxl" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>出水/入水:</td>
                <td><input name="csrs" style="width:200px;"></input></td>
            </tr> 
            <tr>
                <td>类型:</td>
                <td><input name="lx" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>预测比:</td>
                <td><input name="ycb" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>指标类型:</td>
                <td><input name="zbfl" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>指标分类:</td>
                <td><input name="zbmx" style="width:200px;"></td>
            </tr>
            <tr>
                <td>去除率:</td>
                <td><input name="qcl" style="width:200px;"></input></td>
            </tr>
            <tr>
                <td>指标描述:</td>
                <td><input name="zbms" style="width:200px;"></input></td>
            </tr>                           
        </table>
    </form>
</div>
<div style="text-align:center;padding:5px;">
    <a href="javascript:void(0)" onclick="saveUser()" id="btn-save" icon="icon-save">保存</a>
    <a href="javascript:void(0)" onclick="closeWindow()" id="btn-cancel" icon="icon-cancel">取消</a>
</div>

[color=red]JAVA文件[/color]

package com.struts2.jquery.test;

import java.util.ArrayList;
import java.util.List;
import java.sql.*;

import net.sf.json.JSONArray;
import com.struts2.jquery.vo.User;

public class GetAction extends com.struts2.jquery.common.AbstractJSONAction {

private static final long serialVersionUID = 1L;
private JSONArray get;

private String code;
public String getCode() {
    return code;
}

public void setCode(String code) {
    this.code = code;
}
public String  GetInfoAction(){
    Statement st=null;
    Connection conn=null;
    ResultSet rs=null;
    List<User> list = new ArrayList<User>();
    User user = null;
    String dbDrive = "oracle.jdbc.driver.OracleDriver"; //dbDrive;
    String conStr = "jdbc:oracle:thin:@192.168.0.95:1521:orcl"; //conStr;
    try {
        Class.forName(dbDrive);
        conn=DriverManager.getConnection(conStr,"epe","epe"); 
        st=conn.createStatement();
        String sql = "select * from demo_vip where id = "+code+"";
        rs = st.executeQuery(sql);
        while(rs.next()){
            user = new User();
            user.setCode(rs.getInt("id"));
            user.setQybh(rs.getString("qybh"));
            user.setQymc(rs.getString("qymc"));
            user.setSbxh(rs.getString("sbxh"));
            user.setSbmc(rs.getString("sbmc"));
            user.setZcl(rs.getString("zcl"));
            user.setBxl(rs.getString("bxl"));
            user.setCsrs(rs.getString("csrs"));
            user.setLx(rs.getString("lx"));
            user.setYcb(rs.getString("ycb"));
            user.setZbfl(rs.getString("zbfl"));
            user.setZbmx(rs.getString("zbmx"));
            user.setQcl(rs.getString("qcl"));
            user.setZbms(rs.getString("zbms"));
            list.add(user);
        }
        get = JSONArray.fromObject(list);
        System.out.print(get);

    }catch (Exception e) {
        e.printStackTrace();
    }finally{
        try {
            rs.close();
            st.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    } 
    return SUCCESS;
}

public JSONArray getGet() {
    return get;
}

public void seGet(JSONArray get) {
    this.get = get;
}

}

[color=red]配置:[/color]
class="com.struts2.jquery.test.GetAction" method="GetInfoAction">

get

4个回答

[code="java"]

package com.struts2.jquery.test;

import java.util.ArrayList;
import java.util.List;
import java.sql.*;

import net.sf.json.JSONObject;
import com.struts2.jquery.vo.User;

public class GetAction extends com.struts2.jquery.common.AbstractJSONAction {

private static final long serialVersionUID = 1L;
private JOSNObject get;

private String code; 

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}
public String GetInfoAction(){
Statement st=null;
Connection conn=null;
ResultSet rs=null;

    User user = null; 
    String dbDrive = "oracle.jdbc.driver.OracleDriver"; //dbDrive; 
    String conStr = "jdbc:oracle:thin:@192.168.0.95:1521:orcl"; //conStr; 

try {
Class.forName(dbDrive);
conn=DriverManager.getConnection(conStr,"epe","epe");
st=conn.createStatement();
String sql = "select * from demo_vip where id = "+code+"";
rs = st.executeQuery(sql);
while(rs.next()){
user = new User();
user.setCode(rs.getInt("id"));
user.setQybh(rs.getString("qybh"));
user.setQymc(rs.getString("qymc"));
user.setSbxh(rs.getString("sbxh"));
user.setSbmc(rs.getString("sbmc"));
user.setZcl(rs.getString("zcl"));
user.setBxl(rs.getString("bxl"));
user.setCsrs(rs.getString("csrs"));
user.setLx(rs.getString("lx"));
user.setYcb(rs.getString("ycb"));
user.setZbfl(rs.getString("zbfl"));
user.setZbmx(rs.getString("zbmx"));
user.setQcl(rs.getString("qcl"));
user.setZbms(rs.getString("zbms"));
}
get = JSONObject.fromObject(user);
System.out.print(get);

}catch (Exception e) {
e.printStackTrace();
}finally{
try {
rs.close();
st.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return SUCCESS;
}

public JSONObject getGet() { 
    return get; 
} 

public void seGet(JSONObject get) { 
    this.get = get; 
} 

}
[/code]

你的form中要很多行的列表吗?不是的话,用上面这些。

[code="java"]
get = JSONArray.fromObject(list);
[/code]

form 的load只能返回一个json对象吧 不能返回json数组吧

你返回数据时这样的
[code="java"]
{"get":[{"id":1},{"id":2}]}
[/code]

但是应该返回的是这样的
[code="java"]
{"get":{"id":1}}
[/code]

所以你action里面的属性应该是
[code="java"]
private JSONObject get;
中见省略
//返回一个 user对象
get = JSONObject.fromObject(user)
//返回一个user对象的集合,变成json就是一个数组了
//get = JSONObject.fromObject(list)
[/code]

在前台页面上 你直接用
[code="javascript"]
$('#ff').form('load', {
url:"你的URL",
onSubmit: function(){
// do some check
// return false to prevent submit;
},
success:function(data){
//返回的data就直接是你的User对象
//要什么属性就直接点就行了
alert(data.id);
alert(data.qybh);
}
});
[/code]

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐