我更新了这个,因为你建议它似乎没有使用更新的映射运行..doesnt似乎让这个Ext.data.XmlReader的字段映射工作。
Ext.require([
'Ext.data.*',
'Ext.grid.*'
]);
Ext.onReady(function(){
Ext.define('Book',{
extend: 'Ext.data.Model',
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
'Time', 'UserID', 'Type', 'Description','val0'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Book',
autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: 'audit-v2.xml',
// the return will be XML, so lets set up a reader
reader: {
type: 'xml',
// records will have an "Item" tag
//record: 'rows',
// idProperty: 'ASIN',
//totalRecords: '@total'
root: 'Root',
record: 'AuditTrail'
}
}
});
// create the grid
var grid = Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Time", flex: 1, dataIndex: 'Time', sortable: true},
{text: "UserId", width: 180, dataIndex: 'UserId', sortable: true},
{text: "Type", width: 115, dataIndex: 'Type', sortable: true},
{text: "Description", width: 100, dataIndex: 'Description', sortable: true}
{text: "Value", width: 100, dataIndex: 'Value', sortable: true}
],
renderTo:'example-grid',
width: 540,
height: 200
});
});
这是xml
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<AuditTrail>
<Time>2012-01-10 09:27:30 (GMT-05:00)</Time>
<UserID>DX</UserID>
<Type>FY [REC]</Type>
<Description>Server: wamp</Description>
<val0>1</val0>
</AuditTrail>
<AuditTrail>
<Time>2012-01-10 09:27:30 (GMT-05:00)</Time>
<UserID>DX</UserID>
<Type>FY [REC]</Type>
<Description>Server:tomcat</Description>
<val0>1</val0>
</AuditTrail>
<AuditTrail>
<Time>2012-01-10 09:27:30 (GMT-05:00)</Time>
<UserID>DX</UserID>
<Type>FY [REC]</Type>
<Description>Server: apache</Description>
<val0>1</val0>
</AuditTrail>
</Root>
它似乎没有加载xml
由于
答案 0 :(得分:0)
您将阅读器的record
属性设置得过高。在您的情况下,我认为最好将root
设置为Root
,将record
设置为AuditTrail
。另外,在Book
模型上,您应更改mapping
字段的time
以不进行相对查询,即您的记录字段为AuditTrail
,因此您不需要深入查询查询中的某个级别:
// ...
Ext.define('Book',{
extend: 'Ext.data.Model',
fields: ['Time', 'UserID', 'Type', 'Description','val0']
});
// ...
proxy: {
// load using HTTP
type: 'ajax',
url: 'audit-v2.xml',
// the return will be XML, so lets set up a reader
reader: {
type: 'xml',
root: 'Root',
record: 'AuditTrail'
}
}
// ...
您的商店期望数据索引处于AuditTrail
元素的级别,这就是为什么我提到您应该将record
设置为AuditTrail
。