Im stacking with ext js 4 at the very beginning. Im trying to get current user data at application startup using storage. But I do not receive any data from the store, not even returning store.count 0. I found many descriptions of how to create a repository, but not how to access the data in it.
I managed to get the data using an Ext ajax request, but I think it is better to use the storage and I can not avoid it.
My model:
Ext.define('MyApp.model.User', { extend: 'Ext.data.Model', fields: [ 'id', 'username', 'email' ] });
My store looks like this:
Ext.define('MyApp.store.User.CurrentUser', { extend: 'Ext.data.Store', requires: 'MyApp.model.User', model: 'MyApp.model.User', autoLoad: true, proxy: { type: 'ajax', method: 'POST', url: Routing.generate('admin_profile'), reader: { type: 'json', root: 'user' } } });
Returned json:
{ "success":true, "user":[{ "id":1, "username":"r00t", "email":" root@root.root " }] }
And the application:
Ext.application({ name: 'MyApp', appFolder: '/bundles/myadmin/js/app', models: ['MyApp.model.User'], stores: ['MyApp.store.User.CurrentUser'], //autoCreateViewport: true, launch: function() { var currentUser=Ext.create('MyApp.store.User.CurrentUser',{}); /* Ext.Ajax.request({ url : Routing.generate('admin_profile'), method: 'POST', success: function(resp) { var options = Ext.decode(resp.responseText).user; Ext.each(options, function(op) { var user = Ext.create('MyApp.model.User',{id: op.id,username:op.username,email:op.email}); setUser(user); } )} }); */ currentUser.load(); alert(currentUser.count()); } });