Extjs脚本无法显示JSON数据

许若云 发布于 2013/10/24 11:24
阅读 315
收藏 0

脚本:

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);
     alert(gridPanel);
   }}
  ]
 })
});

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>

页面输出

 

JSP能输出结果,html却如图无法显示,求指点

加载中
0
backtract
backtract
firebug调试下 看 请求是否响应了json数据。
返回顶部
顶部