在ExtJS的有實體店面proxy,也Ajax request您可以同時使用。
- Proxies是使用Ext.data.Store處理Ext.data.Model數據的加載和保存。通常開發人員不需要直接創建或與代理交互。一個Ext.data.Connection的
- Ajax單一實例。這個類用於與您的服務器端代碼進行通信。
我已創建並Sencha Fiddle演示。這裏我創建了2個本地json文件(user.json & user1.json)。
我使用存儲代理(來自user.json)和Ext.Ajax的請求(來自user1.json)獲取數據。
希望這會幫助你解決你的問題。
*請注意,這將適用於現代和經典。
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['name', 'email', 'phone']
});
Ext.create('Ext.data.Store', {
storeId: 'userStore',
model: 'User',
proxy: {
type: 'ajax',
url: 'user.json',
reader: {
dataType: 'json',
rootProperty: 'data'
}
}
});
Ext.create('Ext.panel.Panel', {
width: '100%',
renderTo: Ext.getBody(),
padding: 15,
items: [{
xtype: 'button',
margin:5,
text: 'Get Data using Store Load',
handler: function() {
var gridStore = this.up().down('#grid1').getStore();
gridStore.load(function() {
Ext.Msg.alert('Success', 'You have get data from user.json using store.load() method..!');
});
}
}, {
xtype: 'grid',
itemId:'grid1',
title: 'User Data Table1',
store: Ext.data.StoreManager.lookup('userStore'),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: '100%',
}, {
xtype: 'button',
margin:5,
text: 'Get Data using Ajax request',
handler: function() {
var me = this.up(),
gridStore = me.down('#grid2').getStore();
me.down('#grid2').mask('Pleas wait..');
Ext.Ajax.request({
url: 'user1.json',
method: 'GET',
success: function (response) {
me.down('#grid2').unmask();
var data = Ext.decode(response.responseText);
gridStore.loadData(data.data);
Ext.Msg.alert('Success', 'You have get data from user1.json using Ext.Ajax.request method..!');
},
failure: function (response) {
me.down('#grid2').unmask();
//put your failure login here.
}
});
}
}, {
xtype: 'grid',
itemId: 'grid2',
title: 'User Data table2',
store: Ext.create('Ext.data.Store', {
fields: ['name', 'email', 'phone']
}),
columns: [{
text: 'Name',
dataIndex: 'name'
}, {
text: 'Email',
dataIndex: 'email',
flex: 1
}, {
text: 'Phone',
dataIndex: 'phone'
}],
height: 200,
width: '100%',
}]
});
這是文檔中給出的示例,如果沒有在本地計算機上進行適當的設置,則無法立即使用它。首先讓我們知道你有什麼設置,你如何配置Ext js 6在你的機器上運行。如果您使用sencha cmd創建了安裝程序,確保在粘貼單個文件時出現錯誤。 –
我已經創建了使用sencha cmd並運行良好的通用應用程序。而且我也通過文檔的指導創建了登錄表單。現在我需要從數據庫中檢索數據,所以我尋找如何做到這一點。 – Abaij