您好我从服务器返回以下xml: 代码:
我似乎无法正确获取xml商店配置。特别是,我希望能够获得自定义标签:name,intra和referrals,它们是返回的结果集的属性。 非常感谢!
答案 0 :(得分:0)
尝试此代码(将test.xml替换为xml源代码)
// create the Data Store
var store = new Ext.data.Store({
// load using HTTP
url: 'test.xml',
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "customer" tag
record: 'customer',
}, ['id','field1', 'field2', 'field3'])
});
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "id", width: 120, dataIndex: 'id', sortable: true},
{header: "field1", width: 180, dataIndex: 'field1', sortable: true},
{header: "field2", width: 115, dataIndex: 'field2', sortable: true},
{header: "field3", width: 100, dataIndex: 'field3', sortable: true}
],
renderTo:'example-grid',
width:540,
height:200
});
store.load();
为了获得标签:name,intra和referrals我使用Ext.DomQuery,它允许你解析为xml(尝试内部和引用)
Ext.Ajax.request({
url: 'test.xml',
success: function(response){
console.debug(response);
if (Ext.DomQuery.selectNode("/rootNode/name", response.responseXML)) {
var name = Ext.DomQuery.selectValue("/rootNode/name", response.responseXML);
console.debug(name);
}
},
failure: function () { console.log('failure');}
});