ExtJsにはproxyとAjax requestの両方のストアがあります。
- ProxiesはExt.data.Modelデータの読み込みと保存を処理するためにExt.data.Storeで使用されています。通常、開発者はプロキシを直接作成する必要はありません。
- Ajax Ext.data.Connectionのシングルトンインスタンス。このクラスは、サーバー側のコードとの通信に使用されます。
私は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