Extjs store.load无法正常工作

时间:2017-05-16 11:38:55

标签: extjs

我从php获得json编码

{
     "employees": [{
         "Employee_ID": "1",
         "Department_ID": "2",
         "Name": "Bagio",
         "Email": "bagio@gmail.com"
     }, {
         "Employee_ID": "2",
         "Department_ID": "2",
         "Name": "Sinchan",
         "Email": "sinchan@gmail.com"
     }]
 }

当我尝试加载它时,我得不到任何回复。这是我的ExtJs 4.2代码

Ext.onReady(function() {
    Ext.define('Person', {
        extend: 'Ext.data.Model',
        fields: [
            'Employee_ID', 'Department_ID', 'Name', 'Email'
        ]
    });

    // create the Data Store
    var store = Ext.create('Ext.data.Store', {
        model: 'Person',
        autoLoad: true,
        proxy: {
            type: 'memory',
            url: 'example.php',
            reader: {
                type: 'json',
                root: 'employees'
            }
        }
    });
    store.load();
    Ext.create('Ext.grid.Panel', {
        store: store,
        columns: [{
                text: "Employ_id",
                width: 120,
                dataIndex: 'Employee_ID'
            },
            {
                text: "Department_ID",
                width: 380,
                dataIndex: 'Department_ID'
            },
            {
                text: "Name",
                width: 380,
                dataIndex: 'Name'
            },
            {
                text: "Email",
                width: 380,
                dataIndex: 'Email'
            }
        ],
        renderTo: 'example-grid',
        width: 500,
        height: 280
    });
});

1 个答案:

答案 0 :(得分:3)

尝试将商店的代理类型从memory更改为ajax。内存代理通常用于从客户端会话本身加载的数据,而不是从远程源加载。