在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