ExtJS中如何获取后台传递的json数据?
publicStringfindAllProOrders(){Stringjson="";inttotalOrder=0;Stringresult="";try{List...
public String findAllProOrders(){
String json = "";
int totalOrder = 0;
String result = "";
try {
List<ProOrder> proOrderList = proOrderService.findAllProOrders();
if (proOrderList.size()>0) {
totalOrder = proOrderList.size();
json = "{totalProperty:"+totalOrder+",root:[";
for (int i = 0; i < proOrderList.size(); i++) {
ProOrder proOrder = proOrderList.get(i);
json += "{orderNo:'"+proOrder.getOrderNo()+"',price:'"+proOrder.getPrice()+"',createDate:'"+proOrder.getCreateDate()+"'},";
}
json = json.substring(0,json.length()-1);
json += "]}";
System.out.println("查询之后的json数据:"+json);
this.getResponse().getWriter().write(json.toString()); //将json数据响应到页面
result = "success";
}
} catch (IOException e) {
// TODO Auto-generated catch block
result = "error";
e.printStackTrace();
}
return result;
}
Ext代码:
Ext.onReady(function(){
var cm = new Ext.grid.ColumnModel([{
header:'订单编号',
dataIndex:'orderNo'
},{
header:'订单价格',
dataIndex:'price'
},{
header:'创建日期',
dataIndex:'createDate',
width:200
}]);
var store = new Ext.data.Store({
// proxy:new Ext.data.HttpProxy({
// url:'ProOrderServlet'
// }),
/////////////////////////////////这里不知道如何获取数据
reader:new Ext.data.JsonReader({
totalProperty:'totalProperty',
//// root:'root'
},[{
name:'orderNo'
},{
name:'price'
},{
name:'createDate'
}])
});
var grid = new Ext.grid.EditorGridPanel({
renderTo:'grid',
store:store,
cm:cm,
loadMask:true,
width:600,
height:300
});
store.load({
params:{start:0,limit:10}
});
});
然后用Ext显示查询出来的数据,但是不知道怎么把json数据取出来?求高手赐教!在线等..... 展开
String json = "";
int totalOrder = 0;
String result = "";
try {
List<ProOrder> proOrderList = proOrderService.findAllProOrders();
if (proOrderList.size()>0) {
totalOrder = proOrderList.size();
json = "{totalProperty:"+totalOrder+",root:[";
for (int i = 0; i < proOrderList.size(); i++) {
ProOrder proOrder = proOrderList.get(i);
json += "{orderNo:'"+proOrder.getOrderNo()+"',price:'"+proOrder.getPrice()+"',createDate:'"+proOrder.getCreateDate()+"'},";
}
json = json.substring(0,json.length()-1);
json += "]}";
System.out.println("查询之后的json数据:"+json);
this.getResponse().getWriter().write(json.toString()); //将json数据响应到页面
result = "success";
}
} catch (IOException e) {
// TODO Auto-generated catch block
result = "error";
e.printStackTrace();
}
return result;
}
Ext代码:
Ext.onReady(function(){
var cm = new Ext.grid.ColumnModel([{
header:'订单编号',
dataIndex:'orderNo'
},{
header:'订单价格',
dataIndex:'price'
},{
header:'创建日期',
dataIndex:'createDate',
width:200
}]);
var store = new Ext.data.Store({
// proxy:new Ext.data.HttpProxy({
// url:'ProOrderServlet'
// }),
/////////////////////////////////这里不知道如何获取数据
reader:new Ext.data.JsonReader({
totalProperty:'totalProperty',
//// root:'root'
},[{
name:'orderNo'
},{
name:'price'
},{
name:'createDate'
}])
});
var grid = new Ext.grid.EditorGridPanel({
renderTo:'grid',
store:store,
cm:cm,
loadMask:true,
width:600,
height:300
});
store.load({
params:{start:0,limit:10}
});
});
然后用Ext显示查询出来的数据,但是不知道怎么把json数据取出来?求高手赐教!在线等..... 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询