论坛首页 入门讨论版 YUI

关于json数据传回到客户端.jsonReader解析的问题

浏览 614 次
该帖已经被评为新手帖
作者 正文
时间:2007-08-01
js:

/*

* Ext JS Library 1.0.1

* Copyright(c) 2006-2007, Ext JS, LLC.

* licensing@extjs.com

*

* http://www.extjs.com/license

*/



Ext.onReady(function(){

var Plant = Ext.data.Record.create([
// the "name" below matches the tag name to read, except "availDate"
// which is mapped to the tag "availability"
{name: 'sex', type: 'string'},
{name: 'age', type: 'string'},
{name: 'name',type: 'string'}
]);

// create the Data Store
var ds = new Ext.data.Store({
// load using script tags for cross domain, if the data in on the same domain as
// this page, an HttpProxy would be better
proxy: new Ext.data.ScriptTagProxy({
url: './login.do?method=inBook'
}),

// create reader that reads the Topic records
reader: new Ext.data.JsonReader({

}, [
{name: 'sex', mapping: 'sex'},
{name: 'age', mapping: 'age'},
{name: 'name', mapping: 'name'}

],Plant),



// turn on remote sorting
remoteSort: true
});
ds.setDefaultSort('age', 'desc');



// the column model has information about grid columns
// dataIndex maps the column to the specific data field in
// the data store
var cm = new Ext.grid.ColumnModel([{
//id: 'topic', // id assigned so we can apply custom css (e.g. .x-grid-col-topic b { color:#333 })
header: "name",
dataIndex: 'name',
width: 420,
css: 'white-space:normal;'
},{
header: "age",
dataIndex: 'age',
width: 100,
hidden: false
},{
header: "sex",
dataIndex: 'sex',
width: 70,
align: 'right'
}]);

// by default columns are sortable
cm.defaultSortable = true;

// create the editor grid
var grid = new Ext.grid.Grid('topic-grid', {
ds: ds,
cm: cm,
selModel: new Ext.grid.RowSelectionModel({singleSelect:true}),
enableColLock:false,
loadMask: true
});

// make the grid resizable, do before render for better performance
var rz = new Ext.Resizable('topic-grid', {
wrap:true,
minHeight:100,
pinned:true,
handles: 's'
});
rz.on('resize', grid.autoSize, grid);

// render it
grid.render();

var gridFoot = grid.getView().getFooterPanel(true);

// add a paging toolbar to the grid's footer
var paging = new Ext.PagingToolbar(gridFoot, ds, {
pageSize: 25,
displayInfo: true,
displayMsg: 'Displaying topics {0} - {1} of {2}',
emptyMsg: "No topics to display"
});


// trigger the data store load
ds.load({params:{start:0, limit:25, forumId: 4}});


});
/********************************************************/


服务端java处理:
ArrayList list = new ArrayList();
SimpleInfo info = new SimpleInfo();
info.setAge("19");
info.setName("Joe");
info.setSex("male");
SimpleInfo info2 = new SimpleInfo();
info2.setAge("18");
info2.setName("youe");
info2.setSex("female");

list.add(info);
list.add(info2);

response.setContentType("text/xml;charset=utf-8");
net.sf.json.JSONArray jsonArray = net.sf.json.JSONArray.fromObject(list);
System.out.println(jsonArray);
response.getWriter().print("{}" + jsonArray);



前台无法读取服务端传回来的数据?请高人指教?
   
时间:2007-08-05
请各位指教!!!.
   
0 请登录后投票
论坛首页 入门讨论版 YUI

跳转论坛:
JavaEye推荐