データベースから初期化したいストアがありますが、 の標準的な init メソッドが見つかりませんでしたExt.data.Store
。コンポーネントでいくつかの例を見つけましたがStoreManager
、それは私が探しているものではないと思います。アプリの MVC 構造を保持したいのですが、定義したメソッドを使用してストアのデータ フィールドを初期化したいだけです。誰かがその方法を説明できますか?
2903 次
1 に答える
1
私はあなたが間違っていることを理解しているか、あなたの質問は率直です。このようなモデルでストアを構成します。それで全部です。ニーズに合ったプロバイダー (リーダー/ライター) を選択できます。
// Set up a model to use in our Store
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{name: 'age', type: 'int'},
{name: 'eyeColor', type: 'string'}
]
});
Ext.define('YourMVCNameSpace.data.UserStore', {
extend: 'Ext.data.Store',
constructor: function (config) {
config = Ext.Object.merge({}, config);
var me = this;
// do what you need with the given config object (even deletes) before passing it to the parent contructor
me.callParent([config]);
// use me forth on cause the config object is now fully applied
},
model: 'User',
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
autoLoad: true
});
リーダーは、次のような Json の結果を期待することに注意してください。
{"total": 55, "users":["...modeldata.."]}
のようなURLを参照しています
http://localhost/YourAppDomain//users.json
ストアをコントローラ ストア アレイ内に 'User' として配置し、コントローラ内でそれを取得するには、getUserStore()
Ext.StoreMgr.lookup('User'); を使用して Ext.StoreMgr を呼び出すか、直接 Ext.StoreMgr から呼び出します。
慣例により、コントローラー (MVC) は、ストアに設定した storeId をオーバーライドし、名前だけを使用することに注意してください。
于 2012-11-20T08:34:17.187 に答える