问题描述
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 });是需要在这里加上一个url么? 从servlet传递过来的数据就是List 的,到了ext不用转换能直接显示出来么?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'} ] }) });这是servlet中处理String paraId = request.getParameter("parameter"); retStr = dataDictService.getBeanInfo(paraId); underDataString = dataDictService.getListById(paraId);retStr = dataDictService.getBeanInfo(paraId); retStr 是从bean转换过来的,用于显示在Ext.form.TextField的,underDataString = dataDictService.getListById(paraId);是从list转换过来的,格式是这种类型的[{"code":"datadict2","id":4,"name":"数据字典2","parentId":4},{"code":"professiontype_03","id":9,"name":"外语","parentId":4},{"code":"terminateReason_01","id":10,"name":"不可抗力","parentId":4}]我这里的retStr 最初是 out.print(retStr);的,underDataString 怎么办呢? 再加个out.print(underDataString ); ?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();
解决方案
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); }
解决方案二:
ext和后台交互是通过json对象 来转换数据的 你可以是用json-lib第三方开源工具 将 list对象转换成json对象 然后再显示到gridpanel中