2017-04-12 71 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