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数据
------解决方案--------------------贴个数据呗 alert弹出来看下是什么
------解决方案--------------------``囧
js脚本 就是看看你传递回来的值神森马···亲 别玩我啊 你会json jquery js 不知道alert···
------解决方案--------------------主要看你传递到页面的时候有没有数据 数据格式是什么 报错不报错··大概就是个这
------解决方案--------------------