Extjs Grid 绑定XML问题
<script type="text/javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
// 列模型定义了表格所有列的信息,
// dataIndex 将特定的列映射到数据源(Data Store)中的数据列(在后面创建)
var cm = new Ext.grid.ColumnModel([
{
id:'cpuModel',
header: "CPU的类别",
dataIndex: 'cpuModel',
width: 250
},
{
header: "用户使用率",
dataIndex: 'cpuUser',
width: 100
},
{
header: "系统使用率",
dataIndex: 'cpuSys',
width: 100
},
{
header: "当前等待率",
dataIndex: 'cpuWait',
width: 100
},
{
header: "当前空闲率",
dataIndex: 'cpuIdle',
width: 100
},
{
header: "总的使用率",
dataIndex: 'cpuCombined',
width: 95
}
]);
// 默认情况下列是可排序的
cm.defaultSortable = true;
// 定义一个用户对象,这样便于我们动态的添加记录,虽然也可以设置成匿名内置对象
var User = Ext.data.Record.create([
// 下面的 "name" 匹配读到的标签名称, 除了 "birthDay",它被映射到标签 "birth"
{name: 'cpuModel', type: 'string' },
{name: 'cpuUser', type: 'string'},
{name: 'cpuSys' , type: 'string'},
{name: 'cpuWait', type: 'string'},
{name: 'cpuIdle', type: 'string'}, // automatic date conversions
{name: 'cpuCombined', type: 'string'}
]);
// 创建 Data Store
var store = new Ext.data.Store({
// 使用 HTTP 加载
url: '<%=basePath%>servlet/CpuInfoSevlet',
// 因为返回值是 XML, 所以我们创建一个解析器
reader: new Ext.data.XmlReader({
// 记录必须包含 "user" 标签
record: 'CpuInfo'
}, User),
sortInfo:{field:'cpuModel', direction:'ASC'}// 排序信息
});
// 创建编辑器表格
var grid = new Ext.grid.EditorGridPanel({
store: store,
cm: cm,
renderTo: '<%=request.getParameter("serip") %>CPU',
bodyStyle:'width:100%',
autoWidth:true,
autoScroll:true,
height:150,
//autoHeight:true,
autoExpandColumn:'cpuModel',
title:'CPU使用情况',// 标题
frame:true,
selModel: new Ext.grid.RowSelectionModel({singleSelect:false})//设置单行选中模式, 否则将无法删除数据
});
// 触发数据加载
store.load();
});
</script>
<%=basePath%>servlet/CpuInfoSevlet返回的XML没有绑定到Grid上面,但是把返回打印出来的XML放到XML文件中读出是可以绑定到Grid上面的,具体XML如下
<?xml version="1.0" encoding="GBK"?>
<CpuInfoes>
<CpuInfo>
<cpuModel>MYCore(TM)2 Duo CPU P8600 @ 2.40GHz</cpuModel>
<cpuUser>0.0%</cpuUser>
<cpuSys>3.0%</cpuSys>
<cpuWait>0.0%</cpuWait>
<cpuIdle>96.9%</cpuIdle>
<cpuCombined>3.0%</cpuCombined>
</CpuInfo>
</CpuInfoes>
网上有人说servlet返回XML时候去掉XML抬头,我去掉了也不行。我高手帮助