Ext js grid不显示xml数据
var store = new Ext.data.Store({
url: './../../dic/findAll.action',
reader: new Ext.data.XmlReader({
totalRecords: 'totalResults',
record: 'record',
id: 'id',
remoteSort: false
}, [
'id','dmmc','dm','dmz','note'
])
});
var grid = new Ext.grid.GridPanel({
store:store,
columns:[
{header:'流水id',dataIndex:'id',align:'right',sortable:true,width:100},
{header:'代码名称',dataIndex:'dmmc',sortable:true,width:100},
{header:'代码',dataIndex:'dm',sortable:true,width:60},
{header:'代码值',dataIndex:'dmz',sortable:true,width:120},
{header:'备注',dataIndex:'note',sortable:true,width:200}
],
loadMask:true,
stripeRows: true,
sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
bbar:new Ext.PagingToolbar({
pageSize:10,
store:store,
displayInfo:true,
displayMsg:'显示第{0}条到{1}条记录,一共{2}条记录',
emptyMsg:'没有记录'
})
});
store.load({params:{start:0,limit:10}});
2、xml:('./../../dic/findAll.action'打出的xml格式)
<?xml version='1.0' encoding='UTF-8' ?>
<dataset>
<totalRecords>2</totalRecords>
<success>true</success>
<record>
<id>1</id>
<dmmc>sex</dmmc>
<dm>1</dm>
<dmz>男</dmz>
<note>性别</note>
</record>
<record>
<id>2</id>
<dmmc>sex</dmmc>
<dm>2</dm>
<dmz>女</dmz>
<note>性别</note>
</record>
</dataset>
xml的路径没有错,后台显示已经成功调用,就是前台没数据显示~
xml和页面都是utf-8编码,我用json是成功的,但是用xml就不行~ 展开
不显示xml还是不显示grid?
你复制运行一下看看这个。引入Ext的路径自己修改一下
<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>只读显示表格的例子(数据是XML)</title>
<link rel="stylesheet" type="text/css" href="js/extjs/resources/css/ext-all.css"" />
<script type="text/javascript" src="js/extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="js/extjs/ext-all.js"></script>
</head>
<body>
<script>Ext.onReady(function(){ //创建一个Ext存储对象
var store = new Ext.data.Store({
url: 'extjs2-grid2.xml',
reader: new Ext.data.XmlReader({
totalRecords: 'totalResults',
record: 'record',
id: 'id',
remoteSort: false
}, [
'id','dmmc','dm','dmz','note'
])
});
var grid = new Ext.grid.GridPanel({
store:store,
columns:[
{header:'流水id',dataIndex:'id',align:'right',sortable:true,width:100},
{header:'代码名称',dataIndex:'dmmc',sortable:true,width:100},
{header:'代码',dataIndex:'dm',sortable:true,width:60},
{header:'代码值',dataIndex:'dmz',sortable:true,width:120},
{header:'备注',dataIndex:'note',sortable:true,width:200}
],
renderTo:'example-grid',
width:540,
height:200 ,
loadMask:true,
stripeRows: true,
sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
bbar:new Ext.PagingToolbar({
pageSize:10,
store:store,
displayInfo:true,
displayMsg:'显示第{0}条到{1}条记录,一共{2}条记录',
emptyMsg:'没有记录'
})
});
store.load({params:{start:0,limit:10}});
});</script>
<br>
<h3>
只读显示表格的例子(数据是XML)
</h3>
<br>
<br>
<div id="example-grid"></div>
</body>
</html>
------------------------------
extjs2-grid2.xml
<?xml version='1.0' encoding='UTF-8' ?>
<dataset>
<totalRecords>2</totalRecords>
<success>true</success>
<record>
<id>1</id>
<dmmc>sex</dmmc>
<dm>1</dm>
<dmz>男</dmz>
<note>性别</note>
</record>
<record>
<id>2</id>
<dmmc>sex</dmmc>
<dm>2</dm>
<dmz>女</dmz>
<note>性别</note>
</record>
<record>
<id>3</id>
<dmmc>sex</dmmc>
<dm>3</dm>
<dmz>女</dmz>
<note>性别</note>
</record><record>
<id>4</id>
<dmmc>sex</dmmc>
<dm>4</dm>
<dmz>女</dmz>
<note>性别</note>
</record><record>
<id>5</id>
<dmmc>sex</dmmc>
<dm>5</dm>
<dmz>女</dmz>
<note>性别</note>
</record>
</dataset>
换了xml就不行?
那能不能监听Ext.data.Store的load事件,看看有没有数据回来?
或者,你用firebug / httpwatch 看看这几个http请求的返回数据?