tjzero_sapce
2011-05-09 11:20
浏览 309

怎么把servlet传过来的List数据显示到gridpanel中?

[code="java"]DictInfoPanel = function(node, grid){
//获得右侧tab对象
Ext.Ajax.request({
waitMsg : '读取数据。。。',
url : "/datadict/DataDictServlet?parameter="+node.id,
method : "GET",
callback : function(args, success, response) {
var json = response.responseText;
var json = eval("("+json+")");
grid.getForm().findField('dataDictName').setValue(json.name);
grid.getForm().findField('dataDictCode').setValue(json.code);
if(success){
var panel = Ext.getCmp("dataDictCenterPanel");
var tab = panel.findById(node.id);
if(!tab){
tab = panel.add({
id: node.id,
xtype:"panel",
title:node.text,
closable:true,
layout:"fit",
items:[grid]
});
}
panel.setActiveTab(tab);
}
},
scope: this
});

[/code]是需要在这里加上一个url么? 从servlet传递过来的数据就是List 的,到了ext不用转换能直接显示出来么?
[code="java"]var store = new Ext.data.Store({
proxy: new Ext.ux.data.PagingMemoryProxy(underTheData),
remoteSort:true,
reader: new Ext.data.ArrayReader({ fields: [
{name: 'dataName', type: 'string'},
{name: 'dataCode', type: 'string'}
] })
});

[/code]这是servlet中处理
[code="java"]String paraId = request.getParameter("parameter");
retStr = dataDictService.getBeanInfo(paraId);
underDataString = dataDictService.getListById(paraId);
[/code]retStr = dataDictService.getBeanInfo(paraId); retStr 是从bean转换过来的,用于显示在Ext.form.TextField的,underDataString = dataDictService.getListById(paraId);是从list转换过来的,格式是这种类型的[code="java"][{"code":"datadict2","id":4,"name":"数据字典2","parentId":4},{"code":"professiontype_03","id":9,"name":"外语","parentId":4},{"code":"terminateReason_01","id":10,"name":"不可抗力","parentId":4}][/code]我这里的retStr 最初是 out.print(retStr);的,underDataString 怎么办呢? 再加个
out.print(underDataString ); ?
[code="java"]else {
String paraId = request.getParameter("parameter");
retStr = dataDictService.getBeanInfo(paraId);
underDataString = dataDictService.getListById(paraId);
System.out.println("0 - 0 "+underDataString);
}
}
out.print(retStr);
out.close();
[/code]

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • heihei0923 2011-05-09 12:39
    已采纳

    http://json-lib.sourceforge.net/
    List list = ......
    JSONArray jsonArray = new JSONArray();
    if(list!=null)
    for(int i=0;i<list.size();i++){
    Map u = (Map)list.get(i);
    jsonArray.put(u);
    }

    已采纳该答案
    打赏 评论
  • cbcgkx 2011-05-09 11:27

    ext和后台交互是通过json对象 来转换数据的
    你可以是用json-lib第三方开源工具
    将 list对象转换成json对象
    然后再显示到gridpanel中

    打赏 评论

相关推荐 更多相似问题