1

我有一个网格,我试图从 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'
        }
    }
});

然后将解析后的 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'
            }]
        }]
    };
}

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

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

有任何想法吗?现在已经被难住了几天,我要疯了!谢谢。

4

2 回答 2

1

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

于 2012-08-24T19:06:52.627 回答
0

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

于 2012-08-25T04:21:19.520 回答