我有一个网格,我试图从XmlStore填充,该XmlStore是从Xml String填充的。到目前为止,商店似乎正在加载XML,但我无法让网格加载商店。 (即grid.getStore()。getCount()始终为0.
// create the Data Stores for use by the grid
Ext.define('InterfaceModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'id', mapping: 'id' },
{ name: 'InterfaceName', mapping: 'InterfaceName' },
{ name: 'TX_OCTETS', mapping: 'TX_OCTETS' },
{ name: 'TX_BAD_OCTETS', mapping: 'TX_BAD_OCTETS' },
{ name: 'TX_FRM', mapping: 'TX_FRM' },
{ name: 'TX_BAD_FRM', mapping: 'TX_BAD_FRM' },
{ name: 'TX_MCAST', mapping: 'TX_MCAST' },
{ name: 'TX_BCAST', mapping: 'TX_BCAST' },
{ name: 'TX_PAUSE', mapping: 'TX_PAUSE' }
],
idProperty: 'id'
});
我的XML如下:
var gridData = '<?xml version="1.0" encoding="UTF-8"?> <Interfaces> <Interface> <id>1</id> <InterfaceName>GMAC1</InterfaceName> <TX_OCTETS>123234</TX_OCTETS> <TX_BAD_OCTETS>234</TX_BAD_OCTETS> <TX_FRM>234234</TX_FRM> <TX_BAD_FRM>2341</TX_BAD_FRM> <TX_MCAST>23</TX_MCAST> <TX_BCAST>56</TX_BCAST> <TX_PAUSE>8</TX_PAUSE></Interface> <Interface> <id>2</id> <InterfaceName>GMAC2</InterfaceName> <TX_OCTETS>123234</TX_OCTETS> <TX_BAD_OCTETS>234</TX_BAD_OCTETS> <TX_FRM>234234</TX_FRM> <TX_BAD_FRM>2341</TX_BAD_FRM> <TX_MCAST>23</TX_MCAST> <TX_BCAST>56</TX_BCAST> <TX_PAUSE>8</TX_PAUSE></Interface></Interfaces>';
var gridDataXml = (new DOMParser()).parseFromString(gridData,'text/xml');
console.log ('xml', gridDataXml); // everything looks fine
然后我使用内存代理XML阅读器定义我的商店:
var eioaGridStore = new Ext.data.XmlStore({
model: 'InterfaceModel',
autoLoad: true,
proxy: {
type: 'memory',
reader: {
type: 'xml',
root: 'Interfaces',
record: 'Interface',
idProperty: 'id'
}
}
});
然后将解析后的XML DOM加载到商店中:
eioaGridStore.loadRawData(gridDataXml);
如果我在商店上使用getCount(),它会以2正确响应。
从Web Inspector中查看商店显示2个数组(我希望在我的网格中成为行)(原谅格式化)
store
Object
data: Object
allowFunctions: false
events: Object
generation: 3
getKey: function (record) {
hasListeners: Object
items: Array[2]
0: Object
data: Object
dirty: false
events: Object
hasListeners: Object
id: "InterfaceModel-1"
internalId: "1"
modified: Object
phantom: false
raw: Element
store: Object
stores: Array[1]
__proto__: Object
1: Object
length: 2
__proto__: Array[0]
keys: Array[2]
length: 2
map: Object
sorters: Object
__proto__: Object
events: Object
eventsSuspended: 0
filters: Object
groupers: Object
hasListeners: Object
model: function i() {return this.constructor.apply(this,arguments)||null;}
modelDefaults: Object
pageSize: 25
proxy: Object
removed: Array[0]
sorters: Object
totalCount: 2
__proto__: Object
我的网格组件如下:
createGrid: function () {
var me = this;
return {
id: 'eioaGrid',
xtype: 'grid',
border: true,
store: this.eioaGridStore,
columns: [{
header: 'Interface',
dataIndex: 'InterfaceName',
align: 'center',
sortable: true,
tooltip: 'Axxia Interface'
}, {
text: 'OCTETS',
sortable: false,
width: 100,
tooltip: 'Total number of octets in all frames.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_OCTETS',
tooltip: 'Transmitted'
}]
}, {
text: 'BAD OCTETS',
sortable: false,
width: 100,
tooltip: 'Total number of octets in all bad frames.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_BAD_OCTETS',
tooltip: 'Transmitted'
}]
}, {
text: 'FRAMES',
sortable: false,
width: 100,
tooltip: 'Total number of frames.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_FRM',
tooltip: 'Transmitted'
}]
}, {
text: 'BAD FRAMES',
sortable: false,
width: 100,
tooltip: 'Total number of bad frames.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_BAD_FRM',
tooltip: 'Transmitted'
}]
}, {
text: 'MULTICAST',
sortable: false,
width: 100,
tooltip: 'Multicast Frames: good non-pause frames with a multicast destination address which is not the broadcast address.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_MCAST',
tooltip: 'Transmitted'
}]
}, {
text: 'BROADCAST',
sortable: false,
width: 100,
tooltip: 'Broadcast Frames: good frames with the broadcast destination address.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_BCAST',
tooltip: 'Transmitted'
}]
}, {
text: 'PAUSE',
sortable: false,
width: 100,
tooltip: 'Pause Frames: pause frames internally generated by the MAC.',
columns: [{
header: 'TX',
width: 50,
align: 'center',
sortable: true,
dataIndex: 'TX_PAUSE',
tooltip: 'Transmitted'
}]
}]
};
}
稍后,我通过网格商店获取getCount(),然后它返回为空。
console.log('grid store count', Ext.getCmp('eioaGrid').store.getCount());
有什么想法吗?被困了好几天了,我疯了!感谢。
答案 0 :(得分:1)
因为我没有加载您的代码,但是可能会从商店定义中删除自动加载,因为您手动执行此操作只是一个疯狂的猜测?
答案 1 :(得分:0)
我刚发现它...我在设置网格存储时对this.eioaGridStore的引用:不在范围内(未定义)......一切正常工作。