2017-04-12 35 views
-1

我从我的商店加载此数据。任何人都可以解释我如何动态加载数据。通过使用Ajax。如何在extJS网格中获取JSON数据

我的代码

Ext.create('Ext.data.Store', { 
    storeId: 'simpsonsStore', 
    fields:[ 'name', 'email', 'phone'], 
    data: [ 
     { name: 'Lisa', email: '[email protected]', phone: '555-111-1224' }, 
     { name: 'Bart', email: '[email protected]', phone: '555-222-1234' }, 
     { name: 'Homer', email: '[email protected]', phone: '555-222-1244' }, 
     { name: 'Marge', email: '[email protected]', phone: '555-222-1254' } 
    ] 
}); 

Ext.create('Ext.grid.Panel', { 
    title: 'Simpsons', 
    store: Ext.data.StoreManager.lookup('simpsonsStore'), 
    columns: [ 
     { text: 'Name', dataIndex: 'name' }, 
     { text: 'Email', dataIndex: 'email', flex: 1 }, 
     { text: 'Phone', dataIndex: 'phone' } 
    ], 
    height: 200, 
    width: 400, 
    renderTo: Ext.getBody() 
}); 

现在的数据,我会提出一些JSON文件。我的问题是如何在extJS网格商店中获取JSON数据。如何重写STORE代码

+0

嗨大卫是指例如与交代此链接: http://stackoverflow.com/questions/10918030/loading-data-from-a-json-file-成,ExtJS的 – Tejas

回答

1

您需要配置Ext.data.Store以使用Ext.data.proxy.Proxy从服务器加载数据。

Ext.data.proxy.Ajax - 将请求发送到同一域中的服务器

Ext.data.proxy.JsonP - 使用JSON-P将请求发送到服务器上的不同 域

Ext.data.proxy.Rest - 使用的RESTful HTTP方法 (GET/PUT/POST/DELETE)与Ext.data.proxy.Direct 服务器进行通信 - 使用Ext.direct.Manager发送请求

文档:https://docs.sencha.com/extjs/6.2.0/classic/Ext.data.proxy.Proxy.html

代码示例:http://docs.sencha.com/extjs/6.0.2/classic/Ext.data.proxy.Ajax.html