论坛首页 AJAX版 YUI

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

浏览 2863 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2007-08-05
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
YUI-ext的一部请求我没有用过,但是你可以检查一下,自己的请求URL是否有写对
   
0 请登录后投票
时间:2007-08-05
cai555 写道
YUI-ext的一部请求我没有用过,但是你可以检查一下,自己的请求URL是否有写对
前台的请求已经发到服务端了的.就是在前台解析不了后台返回的数据,是否我的jsonReader写的有问题还是....
   
0 请登录后投票
时间:2007-08-09
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
});

proxy: new Ext.data.ScriptTagProxy({
url: './login.do?method=inBook'
}),
只要new ScriptTagProxy对象,前台就会自动访问一次ScriptTagProxy 指定的url路径?
   
0 请登录后投票
时间:2007-08-09
你用个工具(比如TCPmonitor一类)截获一下发送返回的数据,看看数据是否正确。
   
0 请登录后投票
时间:2007-08-20
把 proxy: new Ext.data.ScriptTagProxy 改成

proxy: new Ext.data.HttpProxy

ScriptTagProxy 适用于调用其他机器上的, HttpProxy 是调用本机的
   
0 请登录后投票
时间:2007-08-21
ScriptTagProxy 这个是跨域的
   
0 请登录后投票
时间:2007-08-21
可能你的格试有点问题吧。
   
0 请登录后投票
时间:2007-11-13
看看就好了:http://ivanl.javaeye.com/blog/125460
   
0 请登录后投票
论坛首页 AJAX版 YUI

跳转论坛:
JavaEye推荐
    快速回复 引用上一条消息 (Alt+S)