将JSON数组附加到现有Extjs数据存储网格面板

hl0ma9xz  于 2022-09-26  发布在  其他
关注(0)|答案(1)|浏览(153)

我需要一个简单的例子来重新加载Extjs网格的数据存储,基本要求是用另一个json数组附加Extjs-json数据存储。请帮助我完成这段代码,以便在Extjs Grid面板中加载data2(json对象)。

Ext.onReady(function () {
            var store = Ext.create('Ext.data.Store', {
                storeId: 'employeeStore',
                fields: ['name', 'seniority', 'department'],
                groupField: 'department',
                data: {
                    'employees': [{
                        "name": "Michael Scott",
                        "seniority": 7,
                        "department": "Management"
                    }, {
                        "name": "Dwight Schrute",
                        "seniority": 2,
                        "department": "Sales"
                    }, {
                        "name": "Jim Halpert",
                        "seniority": 3,
                        "department": "Sales"
                    }, {
                        "name": "Kevin Malone",
                        "seniority": 4,
                        "department": "Accounting"
                    }, {
                        "name": "Angela Martin",
                        "seniority": 5,
                        "department": "Accounting"
                    }, {
                        "name": "Angela Martin",
                        "seniority": 5,
                        "department": "Accounting"
                    }]
                },
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        root: 'employees'
                    }
                }
            });
            Ext.create('Ext.grid.Panel', {
                title: 'Employees',
                store: Ext.data.StoreManager.lookup('employeeStore'),
                columns: [{
                    text: 'Name',
                    dataIndex: 'name'
                }, {
                    text: 'Seniority',
                    dataIndex: 'seniority'
                }, {
                    text: 'department',
                    dataIndex: 'department'
                }],

                width: 520,
                height: 275,
                renderTo: Ext.getBody()
            });

            var data2 = {
                'employees': [{
                    "name": "User1",
                    "seniority": 7,
                    "department": "Management"
                },{
                    "name": "User2",
                    "seniority": 7,
                    "department": "Management"
                }]
            };

        });
wfauudbj

wfauudbj1#

Ext.getStore('employeeStore').add(data2.employees);

检查Ext.data。商店#添加文档以了解更多信息。

Ext.getStore()是e1d1e的快捷方式。

相关问题