Ext grid 读不出xml的数据

[code="html"]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题文档
Ext.onReady(function(){ Ext.BLANK_IMAGE_URL = '../extjs/resources/images/default/s.gif'; var dataStore = new Ext.data.Store({ proxy:new Ext.data.HttpProxy({url:'sampledata-sheldon.xml'}), reader:new Ext.data.XmlReader({ record:'Item', id:'ASIN' },['Author', 'Title', 'Manufacturer', 'ProductGroup']) }); dataStore.load(); var colModel = new Ext.grid.ColumnModel([ {header: "Author", width: 120, dataIndex: 'Author'}, {header: "Title", width: 180, dataIndex: 'Title'}, {header: "Manufacturer", width: 115, dataIndex: 'Manufacturer'}, {header: "Product Group", width: 100, dataIndex: 'ProductGroup'} ]); var grid = new Ext.grid.GridPanel({el:'grid',ds:dataStore,cm:colModel}); grid.render(); });




[/code]

sampledata-sheldon.xml
[code="xml"]
<?xml version="1.0" encoding="gb2312"?>


0446613657

http://www.amazon[*SNIP*]JVQEG2


Sidney Sheldon
Warner Books
Book
Are You Afraid of the Dark?

[/code]
只显示了以行表头而已,其他没显示了,请问怎么才能显示出xml中的数据呀

这有个使用xml作为数据源的例子,很详细,也是grid的,你看看就明白了!
[url]http://java2000-net.iteye.com/blog/241968[/url]

record:'Item', 改为

record:'ItemAttributes',

然后grid加个高度

record是表示放在grid的数据 你的数据

Sidney Sheldon

Warner Books

Book

Are You Afraid of the Dark?

这个标签 ItemAttributes 和你record:'Item', 这个对应不上 所以数据无法显示

我调试了你的代码 我这里都出来了

我就把 record:'Item', 改为

record:'ItemAttributes', 然后grid加 height:500 高度太...
然后就好使了 莫非你的url路径 和那个xml所放的位置的路径 不一致??

看这一点
[code="js"]

var dataStore = new Ext.data.Store({

proxy:new Ext.data.HttpProxy({url:'sampledata-sheldon.xml'}),

reader:new Ext.data.XmlReader({

record:'Item',

id:'ASIN'

},['Author', 'Title', 'Manufacturer', 'ProductGroup'])

});

[/code]

你应该把你的 record:'Item', 设置成 record:'ItemAttributes', 因为你那些字段都在这个节点下面。我那个例子已经很明确了!仔细看下

总之你的代码 我就改了我说的那个 其余任何没动

还有你的id id:'ASIN' 这个‘ASIN’不属于ItemAttributes节点下的元素啊。你的xml再整理一下!

再改成
[code="js"]
var ItemAttributes= Ext.data.Record.create([
{name: 'Author'},
{name: 'Manufacturer'},
{name: 'ProductGroup'},
{name: 'Title'},
]);

var dataStore = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:'sampledata-sheldon.xml'}),
reader:new Ext.data.XmlReader({
record:'ItemAttributes'
//id:'ASIN'
},ItemAttributes)
});
dataStore.load();
[/code]

这样试试!

。。。郁闷,是不是压根没请求到你的xml啊?地址对吗?

你使用ext哪个版本?我看3的HttpProxy的构造函数变了,没有url配置项了
HttpProxy( Object conn, Object conn ) 。

你干脆换成
[code="js"]

var dataStore = new Ext.data.Store({

url:'sampledata-sheldon.xml',

reader:new Ext.data.XmlReader({

record:'ItemAttributes'

//id:'ASIN'

},ItemAttributes)

});

dataStore.load();

[/code]

这样。不用代理了!