json无法显示数据,JSP页面输出没问题
JS
function showUrl(value){
return "<a href=http://"+value+" target='_blank'>"+value+"</a>";
}
function formatAge(value,metadata){
if(value > 30) {
metadata.attr = 'style="color:red"';
}
return value;
}
function formateID(value,metadata){
if(value % 2 == 0) {
metadata.attr = 'style="background-color:red"';
}
return value;
}
Ext.onReady(function(){
//记录类型
var Person = new Ext.data.Record.create([
{name:"id",mapping:"id"},
{name:"name",mapping:"name"},
{name:"age",mapping:"age"},
{name:"homePage",mapping:"homePage"}
]);
//存储器
var store = new Ext.data.Store({
url:"JsonServle.jsp",
reader:new Ext.data.JsonReader(
{id:"id"},
Person)
});
store.load();
var sm = new Ext.grid.CheckboxSelectionModel();
//表格面板
var gridPanel = new Ext.grid.GridPanel({
id:"gridPanel",
renderTo:"xu",
title:"人员信息",
width:500,
height:300,
store:store,
columns:[
sm,
{header:"id",dataIndex:"id",sortable:true,renderer:formateID},
{header:"姓名",dataIndex:"name",sortable:true},
{header:"年龄",dataIndex:"age",sortable:true,renderer:formatAge},
{header:"个人主页",dataIndex:"homePage",sortable:true,renderer:showUrl}
],
autoExpandColumn:4,
sm:sm,
bbar:[
{text:"获得所选行",handler:function(){
var msg = "";
var row = gridPanel.getSelectionModel().each(function(rec){
msg = msg + rec.get("id") + "," + rec.get("name") + "," +
rec.get("age") + "," + rec.get("homePage") + "\n";
});
alert(msg);
}}
]
})
});
JSP
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="xu.json.*"%>
<%@ page import="net.sf.json.JSONArray"%>
<%
List<Person>persons = new ArrayList<Person>();
Person person = new Person(1,"张三",20,"www.baid");
Person person2 = new Person(2,"张四",25,"www.baid");
persons.add(person);
persons.add(person2);
JSONArray jsonObject = JSONArray.fromObject(persons);
response.getWriter().write(jsonObject.toString());
%>
<html>
</html>
有布局 就是没显示JSON数据 json
[解决办法]
贴个数据呗 alert弹出来看下是什么
[解决办法]
``囧
js脚本 就是看看你传递回来的值神森马···亲 别玩我啊 你会json jquery js 不知道alert···
[解决办法]
主要看你传递到页面的时候有没有数据 数据格式是什么 报错不报错··大概就是个这
[解决办法]
var myReader = new Ext.data.JsonReader({
totalProperty: "results",
root: "rows",
id: "id"
}, MyRecord);
[解决办法]
打断点 调试 亲。
[解决办法]
亲,你的Ext写的好乱!有点问题!我给你看看我的GridPanel
var ds_recordfile = new Ext.data.Store({
autoLoad : true,
autoSave : false,
pruneModifiedRecords : false,
baseParams : {
limit : page
},
proxy : new Ext.data.HttpProxy({
url : './getRecListChnl.action'
}),
reader : new Ext.data.JsonReader({
root : 'root',
totalProperty : 'totalCount'
}, [{
name : 'id'
}, {
name : 'filenickname'
}, {
name : 'roomname'
}, {
name : 'channelname'
}, {
name : 'recusername'
}, {
name : 'filestatus'
}, {
name : 'starttime'
}, {
name : 'endtime'
}, {
name : 'desc'
}, {
name : 'opt'
}, {
name : 'serverip'
}, {
name : 'fileaddr'
}, {
name : 'port'
}, {
name : 'storageaddr'
}, {
name : 'folderid'
}, {
name : 'plays'
}])
});
grid_recordfile = new Ext.grid.GridPanel({
id : 'recordfile_panel',
height:h,
el:'grid',
width:window.screen.availWidth*0.27,
loadMask : {
msg : '正在加载数据,请稍侯……'
},
stripeRows : true,// 显示斑马线
cm : new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
id : 'id',
header : "录像id",
width : 50,
sortable : true,
dataIndex : 'id',
hidden : true
}, {
id : 'filenickname',
header : "录像文件名",
width : 100,
sortable : true,
dataIndex : 'filenickname',
hidden : true
}, {
id : 'starttime',
header : "开始时间",
width : 150,
sortable : true,
dataIndex : 'starttime',
renderer : function(value, cellmeta, record, rowIndex,
columnIndex, store) {
if (value != null
&& value.replace(/(^\s*)(\s*$)/g, '') != '') {
return value.substring(0, value.length - 2);
} else {
return value;
}
}
}, {
id : 'endtime',
header : "结束时间",
width : 150,
sortable : true,
dataIndex : 'endtime',
renderer : function(value, cellmeta, record, rowIndex,
columnIndex, store) {
if (value != null
&& value.replace(/(^\s*)(\s*$)/g, '') != '') {
return value.substring(0, value.length - 2);
} else {
return value;
}
}
}, {
id : 'channelname',
header : "通道名称",
width :150,
sortable : true,
dataIndex : 'channelname'
}, {
id : 'opt',
header : "操作",
width : 100,
sortable : true,
dataIndex : 'opt',
renderer : function operating(value, cellmeta, record,
rowIndex, columnIndex, store) {
type = record.get('fileaddr').indexOf('.tpc') == -1
? 'xms://'
: 'avms://';
var demand = "<a href=# onclick = Play('"+
type+ record.get('serverip')
+ "/"
+ record.get('fileaddr')
+ "');return false;><img src = 'images/avvod_icons/play.png'></a> ";
var download = "<a href=# onclick = download('"
+ record.get('serverip')
+ "','"
+ record.get('port')
+ "','"
+ record.get('fileaddr')
+ "','"
+ record.get('storageaddr')
+ "','download');return false;><img src = 'images/avvod_icons/dowload.png'></a> ";
return demand+download;
}
},{
id : 'fileaddr',
header : "文件路径",
width : 100,
sortable : true,
dataIndex : 'fileaddr',
hidden : true
}, {
id : 'folderid',
header : "所属文件夹",
width : 50,
sortable : true,
dataIndex : 'folderid',
hidden : true
}]),
store : ds_recordfile,
bbar : new Ext.PagingToolbar({
pageSize : page,
store : ds_recordfile,
displayInfo : true,
afterPageText : '/ {0}',
beforePageText : '页',
firstText : "第一页",
prevText : "上一页",// update
nextText : "下一页",
lastText : "最后页",
refreshText : "刷新",
displayMsg : '显示第 <em>{0}</em> 条到 <em>{1}</em> 条记录,一共 <em>{2}</em> 条',
emptyMsg : "没有记录"
}),
load : ds_recordfile
});
grid_recordfile.render();