ExtJS网格未从Ext.data.XmlStore加载数据



我有一个网格,我正试图从XmlStore填充它,它是从Xml字符串填充的。到目前为止,存储似乎可以很好地加载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'
        }
    }
});

然后将解析后的XMLDOM加载到存储中:

eioaGridStore.loadRawData(gridDataXml);

如果我在存储上获得Count(),它会正确地以2响应。

从Web检查器查看存储显示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'
            }]
        }]
    };
}

稍后,我通过网格的存储获取Count(),它返回为空。

console.log('grid store count', Ext.getCmp('eioaGrid').store.getCount());

有什么想法吗?被困了几天,我快疯了!谢谢

这只是一个猜测,因为我没有加载您的代码,但可能会从存储定义中删除自动加载,因为您是手动执行的?

我刚刚找到它…我在设置网格存储时对this.eoaGridStore的引用:不在范围内(未定义)。。。现在一切正常。

相关内容

  • 没有找到相关文章

最新更新