jquery easyui datagrid+struts2+json读取数据

struts配置文件:使用jsonplugin将属性转换成json对象,extends="json-default" result type要为json

root 是只返回该内容,resultObj与action的属性名字一样,即要返回给页面的值

<package name="bps" extends="json-default">
<action name="bps" class="com.alik.bps.action.BpsAction" method="findBps">
<result type="json">
<param name="root">resultObj</param>
</result>
</action>
<action name="msg" class="com.alik.bps.action.MsgAction" method="findMsg">
<result type="json">
<param name="root">resultObj</param>
</result>
</action>
</package>

action中方法

private JSONObject resultObj;//此处定义为JSONObject是因为datagrid默认接收的为json对象而不是json字符串,如果定义为string 类型的页面读取数据时会报错,我之前报错为rows is not defined

此处省略resultObj的set\get方法

public String findMsg() throws Exception
{
Map map = new HashMap();
ArrayList al = new ArrayList();
for(int i=0;i<3;i++)
{
Map m = new HashMap();
m.put("itemid", String.valueOf(i));
m.put("mction", "a");

al.add(m);
}
map.put("total", 3);
map.put("rows", al);
resultObj=JSONObject.fromObject(map); //将map对象转换成为json对象
System.out.println(resultObj);
return SUCCESS;
}

页面

$('#inVariables').datagrid({
rownumbers:true,
title:'输入',
height:200,
singleSelect:false,
idField:'itemid',
url:'msg.action',
queryParams:{"ComKey":"","SvcKey":""},
columns:[[
{field:'ck',checkbox:true},
{field:'itemid',title:'Item ID',width:100,align:'right',
editor:{
type:'text'},
formatter:function(value){
return '<a href="http://blog.163.com/luckcq@yeah/blog/#" οnclick="insertAtCaret('+value+')">'+value+'</a>';
}
},
{field:'mction',title:'Action',width:100,align:'center',
formatter:function(value,row,index){
if (row.editing){
var s = '<a href="http://blog.163.com/luckcq@yeah/blog/#" οnclick="saverow('+index+',\'inVariables\')">保存</a> ';
var c = '<a href="http://blog.163.com/luckcq@yeah/blog/#" οnclick="cancelrow('+index+',\'inVariables\')">取消</a>';
return s+c;
} else {
var e = '<a href="http://blog.163.com/luckcq@yeah/blog/#" οnclick="editrow('+index+',\'inVariables\')">修改</a> ';
var rowid;
if(row.itemid=='')
{
rowid='null';
}
else
rowid=row.itemid;
var d = '<a href="http://blog.163.com/luckcq@yeah/blog/#" οnclick="deleterow('+index+',\'inVariables\','+rowid+')">删除</a>';
return e+d;
}
}
}
]],
toolbar:[{
text:'增加行',
iconCls:'icon-add',
handler:function(){
addRow('inVariables');
}
},{
text:'删除多行',
iconCls:'icon-cut',
handler:function(){deleteRows('inVariables');}
}],
onBeforeEdit:function(index,row){
row.editing = true;
$('#inVariables').datagrid('refreshRow', index);
},
onAfterEdit:function(index,row){
row.editing = false;
$('#inVariables').datagrid('refreshRow', index);
},
onCancelEdit:function(index,row){
row.editing = false;
$('#inVariables').datagrid('refreshRow', index);
},
onClickRow:function(index,row){
newDG(row);
}
});

PS:This blog is copy form the web, some of the contents is not correct, just paste on my blog for further reference
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值